R
Robert
Hi,
I thought I pretty much understood the whole prototype chain stuff,
but now I stumbled upon a difference between IE and Firefox, that
is totally confusing me.
An example....
************************
function MyObject()
{
}
MyObject.prototype.open = function open()
{
alert("open");
}
function test()
{
var obj = new MyObject();
obj.open();
window.open("http://www.google.com/", "Google");
}
************************
Notice that I name the function assigned to open. I do this because
I noticed that it can be convenient for stacktraces. Instead of
seeing an anonymous function, I can see the name of it.
Calling test in Firefox will give one "open" alert and one new window,
as I expected.
In Internet Explorer however I will get two "open" alerts!
Somehow the open method of the window object has been overwritten.
Changing the prototype method assignment to
MyObject.prototype.open = function()
"fixes" it, but I want to know why that name causes it to overwrite the
window open method.
And is there any other way to give a name to the method, so it is shown in
any stacktrace?
Kind regards,
Robert
I thought I pretty much understood the whole prototype chain stuff,
but now I stumbled upon a difference between IE and Firefox, that
is totally confusing me.
An example....
************************
function MyObject()
{
}
MyObject.prototype.open = function open()
{
alert("open");
}
function test()
{
var obj = new MyObject();
obj.open();
window.open("http://www.google.com/", "Google");
}
************************
Notice that I name the function assigned to open. I do this because
I noticed that it can be convenient for stacktraces. Instead of
seeing an anonymous function, I can see the name of it.
Calling test in Firefox will give one "open" alert and one new window,
as I expected.
In Internet Explorer however I will get two "open" alerts!
Somehow the open method of the window object has been overwritten.
Changing the prototype method assignment to
MyObject.prototype.open = function()
"fixes" it, but I want to know why that name causes it to overwrite the
window open method.
And is there any other way to give a name to the method, so it is shown in
any stacktrace?
Kind regards,
Robert