A
Arthaey Angosii
I'm trying to use Object.prototype to define new functions on my
objects. I have a small test case HTML file online at
http://www.arthaey.com/test.html, also reproduced below:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
Object.prototype.foo = foo;
function foo() {return "Foo!";}
function test() {
alert("\n\nWINDOW: " + this.foo +
"\n\nPARA: " + document.getElementById("bar").foo);
}
</script>
</head>
<body onload="test();">
<pre id="bar">
<!-- this page's HTML code goes here, for demo/test case
purposes -->
</pre>
</body>
</html>
It works in Firefox but I get the following Javascript error in
Firefox's Javascript console:
Error: [Exception... "'Error: No menu commaner found for URL:
http://www.arthaey.com/test.html' when calling method:
[nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c
(NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
Then, in IE, this.foo is properly defined, but
document.getElementById("bar").foo is undefined. Is there some kind of
order-of-definition differences that causes bar's function to be
defined in one browser but not the other? Does anyone know what's
causing the Firefox error or how to fix it?
Thanks,
Arthaey
objects. I have a small test case HTML file online at
http://www.arthaey.com/test.html, also reproduced below:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
Object.prototype.foo = foo;
function foo() {return "Foo!";}
function test() {
alert("\n\nWINDOW: " + this.foo +
"\n\nPARA: " + document.getElementById("bar").foo);
}
</script>
</head>
<body onload="test();">
<pre id="bar">
<!-- this page's HTML code goes here, for demo/test case
purposes -->
</pre>
</body>
</html>
It works in Firefox but I get the following Javascript error in
Firefox's Javascript console:
Error: [Exception... "'Error: No menu commaner found for URL:
http://www.arthaey.com/test.html' when calling method:
[nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c
(NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "<unknown>" data: no]
Then, in IE, this.foo is properly defined, but
document.getElementById("bar").foo is undefined. Is there some kind of
order-of-definition differences that causes bar's function to be
defined in one browser but not the other? Does anyone know what's
causing the Firefox error or how to fix it?
Thanks,
Arthaey