Exception when creating another object - Javascript

This is a discussion on Exception when creating another object - Javascript ; 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 = ...

+ Reply to Thread
Results 1 to 8 of 8

Exception when creating another object

  1. Default Exception when creating another object

    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


  2. Default Re: Exception when creating another object

    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>

  3. Default Re: Exception when creating another object

    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/

  4. Default Re: Exception when creating another object

    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/

  5. Default Re: Exception when creating another object

    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/

  6. Default Re: Exception when creating another object

    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

  7. Default Re: Exception when creating another object

    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

  8. Default Re: Exception when creating another object

    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/

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 09-06-2007, 05:01 AM
  2. Replies: 1
    Last Post: 08-09-2007, 10:00 AM
  3. Replies: 3
    Last Post: 06-22-2007, 06:31 AM
  4. Creating a derived object from a base object
    By Application Development in forum CSharp
    Replies: 3
    Last Post: 12-16-2006, 05:23 PM
  5. Creating a MODIFY exception fails
    By Application Development in forum Microsoft Exchange
    Replies: 1
    Last Post: 02-15-2006, 08:35 PM