llegal operation on WrappedNative prototype object - Javascript

This is a discussion on llegal operation on WrappedNative prototype object - Javascript ; Hi, I get an error when I try to use function pointer on the build-in methods. Here's my code sample: var dce = document.createElement; var divEle = dce("div"); Firefox throws an error saying : uncaught exception: [Exception... "Illegal operation on ...

+ Reply to Thread
Results 1 to 8 of 8

llegal operation on WrappedNative prototype object

  1. Default llegal operation on WrappedNative prototype object

    Hi,
    I get an error when I try to use function pointer on the build-in
    methods. Here's my code sample:

    var dce = document.createElement;
    var divEle = dce("div");

    Firefox throws an error saying : uncaught exception: [Exception...
    "Illegal operation on WrappedNative prototype object" nsresult:
    "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame

    I am using Firefox : Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US;
    rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7

    OS: Windows Server 2003.

    Please let me know if there is any fix for this. A code sample would
    really help.

    Thanks,
    Sampat.

  2. Default Re: llegal operation on WrappedNative prototype object

    On Nov 20, 12:27 pm, Sampat <sampatdi...@gmail.com> wrote:
    > Hi,
    > I get an error when I try to use function pointer on the build-in
    > methods. Here's my code sample:
    >
    > var dce = document.createElement;
    > var divEle = dce("div");
    >
    > Firefox throws an error saying : uncaught exception: [Exception...
    > "Illegal operation on WrappedNative prototype object" nsresult:
    > "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame
    >
    > I am using Firefox : Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US;
    > rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7
    >
    > OS: Windows Server 2003.
    >
    > Please let me know if there is any fix for this. A code sample would
    > really help.


    Try instead:

    var dce = function(tagName){
    return document.createElement(tagName);
    }


    However, the usual approach is to write a function that takes not only
    the tag name, but also attributes to set:

    var dce = function(tagName, attributes) {
    var x = document.createElement(tagName);

    /* Depending on the tag name and attributes
    ** in the attribute object, set x[att] = attributes[att]
    */
    }

    var newElement = dce('div',{id:'foo', className:'fooClass'});


    --
    Rob

  3. Default Re: llegal operation on WrappedNative prototype object

    On Nov 20, 3:36 pm, RobG <rg...@iinet.net.au> wrote:
    [...]
    > However, the usual approach is to write a function that takes not only
    > the tag name, but also attributes to set:
    >
    > var dce = function(tagName, attributes) {
    > var x = document.createElement(tagName);
    >
    > /* Depending on the tag name and attributes
    > ** in the attribute object, set x[att] = attributes[att]
    > */


    return x;

    > }
    >
    > var newElement = dce('div',{id:'foo', className:'fooClass'});



    --
    Rob


  4. Default Re: llegal operation on WrappedNative prototype object

    Sampat wrote:

    > Hi,
    > I get an error when I try to use function pointer on the build-in
    > methods. Here's my code sample:
    >
    > var dce = document.createElement;
    > var divEle = dce("div");


    Why not the following?

    var divEle = document.createElement("div");

    Mick


    >
    > Firefox throws an error saying : uncaught exception: [Exception...
    > "Illegal operation on WrappedNative prototype object" nsresult:
    > "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame
    >
    > I am using Firefox : Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US;
    > rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7
    >
    > OS: Windows Server 2003.
    >
    > Please let me know if there is any fix for this. A code sample would
    > really help.
    >
    > Thanks,
    > Sampat.


  5. Default Re: llegal operation on WrappedNative prototype object

    On Nov 20, 7:59 am, Michael White <m...@mickweb.com> wrote:
    > Sampat wrote:
    > > Hi,
    > > I get an error when I try to use function pointer on the build-in
    > > methods. Here's my code sample:

    >
    > > var dce = document.createElement;
    > > var divEle = dce("div");

    >
    > Why not the following?
    >
    > var divEle = document.createElement("div");
    >
    > Mick
    >
    >
    >
    >
    >
    > > Firefox throws an error saying : uncaught exception: [Exception...
    > > "Illegal operation on WrappedNative prototype object" nsresult:
    > > "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame

    >
    > > I am using Firefox : Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US;
    > > rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7

    >
    > > OS: Windows Server 2003.

    >
    > > Please let me know if there is any fix for this. A code sample would
    > > really help.

    >
    > > Thanks,
    > > Sampat.- Hide quoted text -

    >
    > - Show quoted text -


    Because I want to create the element multiple times in my javascript
    and it would reduce the js file size by specifying dce('element')
    instead of document.createElement('element').


  6. Default Re: llegal operation on WrappedNative prototype object

    Sampat said the following on 11/20/2007 6:19 PM:
    > On Nov 20, 7:59 am, Michael White <m...@mickweb.com> wrote:
    >> Sampat wrote:
    >>> Hi,
    >>> I get an error when I try to use function pointer on the build-in
    >>> methods. Here's my code sample:
    >>> var dce = document.createElement;
    >>> var divEle = dce("div");

    >> Why not the following?
    >>
    >> var divEle = document.createElement("div");


    <snip>

    > Because I want to create the element multiple times in my javascript
    > and it would reduce the js file size by specifying dce('element')
    > instead of document.createElement('element').


    If the aim is to prevent typo's then write a wrapper function as Rob
    suggested. But, trying to create a wrapper for the sake of file size is
    almost self-defeating. To save those 19 characters, and it make any real
    difference in the file size, you would have to be creating at least
    1,000 or so div elements. If you are creating that many, your page is
    fubar'ed before you started.

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

  7. Default Re: llegal operation on WrappedNative prototype object

    On Nov 20, 4:29 pm, Randy Webb <HikksNotAtH...@aol.com> wrote:
    > Sampat said the following on 11/20/2007 6:19 PM:
    >
    > > On Nov 20, 7:59 am, Michael White <m...@mickweb.com> wrote:
    > >> Sampat wrote:
    > >>> Hi,
    > >>> I get an error when I try to use function pointer on the build-in
    > >>> methods. Here's my code sample:
    > >>> var dce = document.createElement;
    > >>> var divEle = dce("div");
    > >> Why not the following?

    >
    > >> var divEle = document.createElement("div");

    >
    > <snip>
    >
    > > Because I want to create the element multiple times in my javascript
    > > and it would reduce the js file size by specifying dce('element')
    > > instead of document.createElement('element').

    >
    > If the aim is to prevent typo's then write a wrapper function as Rob
    > suggested. But, trying to create a wrapper for the sake of file size is
    > almost self-defeating. To save those 19 characters, and it make any real
    > difference in the file size, you would have to be creating at least
    > 1,000 or so div elements. If you are creating that many, your page is
    > fubar'ed before you started.
    >
    > --
    > Randy
    > Chance Favors The Prepared Mind
    > comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
    > Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/


    I am using this wrapper function as a common function in a common js
    file which is used accross the site. The method would be called from
    50 different js files used accross multiple pages.

  8. Default Re: llegal operation on WrappedNative prototype object

    Sampat said the following on 11/21/2007 1:23 PM:

    <snip>

    > I am using this wrapper function as a common function in a common js
    > file which is used accross the site. The method would be called from
    > 50 different js files used accross multiple pages.


    If it is in a common file, then it will save from having it in multiple
    files but that still won't make a huge impact on file size.

    --
    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. prototypal inheritance: the prototype object
    By Application Development in forum Javascript
    Replies: 8
    Last Post: 12-02-2007, 12:13 PM
  2. Is it not well to extend Object.prototype derictly?
    By Application Development in forum Javascript
    Replies: 3
    Last Post: 08-12-2007, 01:41 PM
  3. Replies: 6
    Last Post: 07-26-2007, 06:56 PM
  4. Re: Operation is not allowed when the object is closed
    By Application Development in forum ADO DAO RDO RDS
    Replies: 0
    Last Post: 01-10-2006, 09:49 AM
  5. Prototype object calling c# code problem
    By Application Development in forum Javascript
    Replies: 8
    Last Post: 04-27-2005, 11:27 AM