Exception when creating another object

E

Erik Wegner

Hi,

on writing some nice javascript classes, I stumble upon the following
error, which I find no hint for:

First, there is an object:

function pic(bname, x, y) {
this.x = x;
this.y = y;
this.objektid = bname;

this.positionXY = function(posx, posy) {
// some code
}

this.move = function() {
// some code
}
}

When loading my sample page, I create 7 objects by calling
apic = new pic("examplename", 150, 150);
which works fine.

After a while, I click on a hyperlink, which calls a javascript
function. Within this function, I repeat the creation step exactly
(copy&paste) as above, but now Firefox presents the error message:

Fehler: uncaught exception: [Exception... "Cannot convert
WrappedNative to function" nsresult: "0x8057000d
(NS_ERROR_XPC_CANT_CONVERT_WN_TO_FUN)" location: "JS frame ::
http://localhost/~user/project/js/lib.js :: anonymous :: line 255"
data: no]

Line 255 looks like
apic = new pic("examplename", 150, 150);
and gets already called 7 times before my eightth call which then
fails. I have no idea where to look for a solution.

Thanks a lot for any suggestions!

Greetings
Erik
 
T

Thomas 'PointedEars' Lahn

Erik said:
on writing some nice javascript classes,

You don't. You are dealing with programming languages that support
"only" prototype-based inheritance.
I stumble upon the following error, which I find no hint for:

First, there is an object:

function pic(bname, x, y) {
this.x = x;
this.y = y;
this.objektid = bname;

this.positionXY = function(posx, posy) {
// some code
}

this.move = function() {
// some code
}
}

When loading my sample page, I create 7 objects by calling
apic = new pic("examplename", 150, 150);
which works fine.

However, constructor identifiers should start with a capital letter to
distinguish them from other methods easily.
After a while, I click on a hyperlink, which calls a javascript
function. Within this function, I repeat the creation step exactly
(copy&paste) as above, but now Firefox presents the error message:

Fehler: uncaught exception: [Exception... "Cannot convert
WrappedNative to function" nsresult: "0x8057000d
(NS_ERROR_XPC_CANT_CONVERT_WN_TO_FUN)" location: "JS frame ::
http://localhost/~user/project/js/lib.js :: anonymous :: line 255"
data: no]

Line 255 looks like
apic = new pic("examplename", 150, 150);
and gets already called 7 times before my eightth call which then
fails. I have no idea where to look for a solution.

A quick Google search for the error code NS_ERROR_XPC_CANT_CONVERT_WN_TO_FUN
would have revealed (as your notion of classes above already indicated) that
your problem is the infamous Prototype library. Stop using that and all of
its deluded offsprings (like Script.aculo.us) and many of your problems will
go away.


PointedEars
 
M

Martin Honnen

Erik said:
Fehler: uncaught exception: [Exception... "Cannot convert
WrappedNative to function" nsresult: "0x8057000d
(NS_ERROR_XPC_CANT_CONVERT_WN_TO_FUN)" location: "JS frame ::
http://localhost/~user/project/js/lib.js :: anonymous :: line 255"
data: no]

Line 255 looks like
apic = new pic("examplename", 150, 150);
and gets already called 7 times before my eightth call which then
fails. I have no idea where to look for a solution.

Do you have an element in the page with id="pic"? And is that HTML
document rendered in quirks mode?
 
M

Martin Honnen

Martin said:
Do you have an element in the page with id="pic"? And is that HTML
document rendered in quirks mode?

Could also be an element with name="id" (e.g <img name="pic" ...>). And
quirks mode is not relevent, you are probably using an event handler
e.g. <a onclick="apic = new pic(...)"> and in such an event handler the
document object and with that document.pic sits in the scope chain so
your code is not accessing the function named pic but rather an element
object named pic.
 
J

John G Harris

However, constructor identifiers should start with a capital letter to
distinguish them from other methods easily.
<snip>

It's class names that should start with a capital letter. But javascript
doesn't have classes ...

John
 
T

Thomas 'PointedEars' Lahn

John said:
[...] Thomas 'PointedEars' Lahn said:
However, constructor identifiers should start with a capital letter to
distinguish them from other methods easily.

It's class names that should start with a capital letter.

That is also true. It does not invalidate my statement though.
But javascript doesn't have classes ...

That is only partially true.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top