Tuesday, June 4, 2024
49
rated 0 times [  53] [ 4]  / answers: 1 / hits: 121400  / 13 Years ago, tue, may 31, 2011, 12:00:00

error



'nuff said. I have absolutely no clue why using alert() there wouldn't work. It works perfectly in Firefox, but gives that error in Chrome.


More From » google-chrome

 Answers
11
window.alert = null;
alert('test'); // fail
delete window.alert; // true
alert('test'); // win


window is an instance of DOMWindow, and by setting something to window.alert, the correct implementation is being shadowed, i.e. when accessing alert it is first looking for it on the window object. Usually this is not found, and it then goes up the prototype chain to find the native implementation. However, when manually adding the alert property to window it finds it straight away and does not need to go up the prototype chain. Using delete window.alert you can remove the window own property and again expose the prototype implementation of alert. This may help explain:



window.hasOwnProperty('alert'); // false
window.alert = null;
window.hasOwnProperty('alert'); // true
delete window.alert;
window.hasOwnProperty('alert'); // false

[#91963] Sunday, May 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
armandoh

Total Points: 208
Total Questions: 94
Total Answers: 112

Location: South Sudan
Member since Sun, Jul 11, 2021
3 Years ago
armandoh questions
Wed, Apr 13, 22, 00:00, 2 Years ago
Sat, Jan 30, 21, 00:00, 3 Years ago
Fri, Jun 5, 20, 00:00, 4 Years ago
Sun, Dec 22, 19, 00:00, 5 Years ago
;