SearchSearch   

Exception when creating another object

 
   Webmaster Forums (Home) -> Javascript RSS
Next:  Suggestions needed for list of links  
Author Message
Erik Wegner

External


Since: Aug 12, 2007
Posts: 1



(Msg. 1) Posted: Sun Aug 12, 2007 4:00 pm
Post subject: Exception when creating another object
Archived from groups: comp>lang>javascript (more info?)

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
Back to top
Thomas 'PointedEars' Lahn

External


Since: Sep 05, 2004
Posts: 3405



(Msg. 2) Posted: Sun Aug 12, 2007 6:09 pm
Post subject: Re: Exception when creating another object
Archived from groups: per prev. post (more info?)

Erik Wegner wrote:
> 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
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>
Back to top
Randy Webb

External


Since: Aug 24, 2004
Posts: 4981



(Msg. 3) Posted: Sun Aug 12, 2007 6:09 pm
Post subject: Re: Exception when creating another object
Archived from groups: per prev. post (more info?)

Thomas 'PointedEars' Lahn said the following on 8/12/2007 12:09 PM:
> Erik Wegner wrote:
>> on writing some nice javascript classes,
>
> You don't. You are dealing with programming languages that support
> "only" prototype-based inheritance.

Which is totally irrelevant to the question and saying a million times
that JS doesn't have "classes" or "Associative Arrays" won't change the
fact that people call them "classes" and "Associative Arrays". Let them
call them what they want and get used to it because it isn't going to
change.

<snip>

>> 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.

You can name and capitalize them however you want and it won't make a
hill of beans difference. What and how you name functions (as long as it
doesn't clash with a built in function/object name) is totally up to the
programmer and what they choose to use.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Back to top
Martin Honnen

External


Since: Aug 13, 2004
Posts: 2079



(Msg. 4) Posted: Sun Aug 12, 2007 6:48 pm
Post subject: Re: Exception when creating another object
Archived from groups: per prev. post (more info?)

Erik Wegner wrote:

> 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?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Back to top
Martin Honnen

External


Since: Aug 13, 2004
Posts: 2079



(Msg. 5) Posted: Sun Aug 12, 2007 6:53 pm
Post subject: Re: Exception when creating another object
Archived from groups: per prev. post (more info?)

Martin Honnen wrote:

> 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.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Back to top
John G Harris

External


Since: May 28, 2006
Posts: 213



(Msg. 6) Posted: Mon Aug 13, 2007 9:14 pm
Post subject: Re: Exception when creating another object
Archived from groups: per prev. post (more info?)

On Sun, 12 Aug 2007 at 18:09:27, in comp.lang.javascript, Thomas
'PointedEars' Lahn wrote:

<snip>
>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
--
John Harris
Back to top
Thomas 'PointedEars' Lahn

External


Since: Sep 05, 2004
Posts: 3405



(Msg. 7) Posted: Mon Aug 13, 2007 11:06 pm
Post subject: Re: Exception when creating another object
Archived from groups: per prev. post (more info?)

John G Harris wrote:
> [...] Thomas 'PointedEars' Lahn wrote:
>> 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
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Back to top
Randy Webb

External


Since: Aug 24, 2004
Posts: 4981



(Msg. 8) Posted: Mon Aug 13, 2007 11:06 pm
Post subject: Re: Exception when creating another object
Archived from groups: per prev. post (more info?)

Thomas 'PointedEars' Lahn said the following on 8/13/2007 5:06 PM:
> John G Harris wrote:
>> [...] Thomas 'PointedEars' Lahn wrote:
>>> 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.

Your statement wasn't true to start with so it didn't need invalidating.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Back to top
Display posts from previous:   
       Webmaster Forums (Home) -> Javascript
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum