Why can we delete some built-in properties of global object?
Posted
by
demix
on Programmers
See other posts from Programmers
or by demix
Published on 2011-11-23T09:39:22Z
Indexed on
2011/11/24
2:19 UTC
Read the original article
Hit count: 298
JavaScript
I'm reading es5 these days and find that [[configurable]] attribute in some built-in properties of global object is set to true which means we can delete these properties.
For example:
the join method of Array.prototype object have attributes
{[[Writable]]:true, [[Enumerable]]: false, [[Configurable]]: true}
So we can easily delete the join method for Array like:
delete Array.prototype.join;
alert([1,2,3].join);
The alert will display undefined
in my chromium 17,firefox 9 ,ie 10,even ie6;
In Chrome 15 & safari 5.1.1 the [[configurable]] attribute is set to true and delete result is also true but the final result is still function(){[native code]}
. Seems like this is a bug and chromium fix it.
I haven't notice that before. In my opinion, delete built-in functions in user's code is dangerous, and will bring out so many bugs when working with others.So why ECMAScript make this decision?
© Programmers or respective owner