admin管理员组文章数量:1305514
Lets say we have alert method of window object. I would like to enhance it with nice alertbox.
Also I want to save the existing alert method so that we can switch back once our application is over.
Something like this, but its throwing error in firefox console.
window.prototype.alert = function(){
}
Lets say we have alert method of window object. I would like to enhance it with nice alertbox.
Also I want to save the existing alert method so that we can switch back once our application is over.
Something like this, but its throwing error in firefox console.
window.prototype.alert = function(){
}
Share
Improve this question
edited Jan 18, 2012 at 11:50
Milad Naseri
4,1181 gold badge29 silver badges40 bronze badges
asked Jan 18, 2012 at 11:45
indianwebdevilindianwebdevil
5,1277 gold badges40 silver badges53 bronze badges
2 Answers
Reset to default 5There is no window.prototype
object. window
is a global object of javascript context and it is not created from the prototype.
However, what you want to do is achievable with the following code:
window.old_alert = window.alert;
window.alert = function(txt) {
// do what you need
this.old_alert(txt);
}
You can;
var base = window.alert;
window.alert = function(message) {
document.getElementById("myalertwidget").innerHTML = message;
return base.apply(this, arguments);
};
本文标签: overridinghow to overwrite a builtin method of javascript native objectsStack Overflow
版权声明:本文标题:overriding - how to overwrite a builtin method of javascript native objects - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741803174a2398343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论