Re: Window load/unload calling Object.prototype extension method.
- From: Garrett Smith <dhtmlkitchen@xxxxxxxxx>
- Date: Sat, 11 Apr 2009 20:55:05 -0700
Thomas 'PointedEars' Lahn wrote:
Garrett Smith wrote:<script type="text/javascript">
Object.prototype.zvt_hello = function() {
alert(this.constructor);
}
var d = new Date();
d.zvt_hello();
var i = new Number();
i.zvt_hello();
</script>
- results in two alerts:
function Date(){
[native code]
}
function Number(){
[native code]
}
<aside>
Those don't conform to ECMA 262r3
You are mistaken because alert() is a host method (of Window objects, and
should therefore be called window.alert()). It may display anything there.
The alert method converts its argument to a string value.
window.alert( '' + this.constructor );
would have the same effect of popping up an alert box with the [native code] function representations.
<aside>
Although this is invalid, certain libraries actually depend on this behavior. Dojo, Mootools, and Qooxdoo, for example perform tests to see if the result of converting an object to a string (using its toString) contains "[native code]".
This practice is not just non-standard, even if the [native code] were allowed it is fallible on two counts that have been discussed.
</aside>
Garrett
.
- Follow-Ups:
- References:
- Window load/unload calling Object.prototype extension method.
- From: Zvt.Fred
- Re: Window load/unload calling Object.prototype extension method.
- From: Thomas 'PointedEars' Lahn
- Re: Window load/unload calling Object.prototype extension method.
- From: Zvt.Fred
- Re: Window load/unload calling Object.prototype extension method.
- From: Garrett Smith
- Re: Window load/unload calling Object.prototype extension method.
- From: Thomas 'PointedEars' Lahn
- Window load/unload calling Object.prototype extension method.
- Prev by Date: Re: Array of attribute values from object array?
- Next by Date: Re: which getElementByClass implementations are favored?
- Previous by thread: Re: Window load/unload calling Object.prototype extension method.
- Next by thread: Re: Window load/unload calling Object.prototype extension method.
- Index(es):
Relevant Pages
|