llegal operation on WrappedNative prototype object

S

Sampat

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

RobG

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'});
 
R

RobG

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;
 
S

Sampat

Sampat said:
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').
 
S

Sampat

Sampat said the following on 11/20/2007 6:19 PM:




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.
 

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,772
Messages
2,569,591
Members
45,100
Latest member
MelodeeFaj
Top