为什么 alert 在 safari 中定义了两次?
Safari 5.1.7(7534.57.2)
window.hasOwnProperty('alert'); //true
var w = Object.getPrototypeOf(window);
w.hasOwnProperty('alert'); //true
其他浏览器:Chrome 24.0.1312.52 m,FireFox 18.0,IE 9.0.8112.16421CO,Opera 12.12 1707
window.hasOwnProperty('alert'); //false
var w = Object.getPrototypeOf(window);
w.hasOwnProperty('alert'); //true
最佳答案
这意味着在 Safari 中,他们将警报设置为原型(prototype)和窗口实例上的函数。
function Window() {
this.alert = function() { //code here };
}
Window.prototype.alert = function() { //code here };
而在其他浏览器中,它们只会完成原型(prototype)声明。
关于javascript - 为什么 alert 在 safari 中定义了两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14305947/