how to overwrite a builtin method of javascript native objects

梦想与她 提交于 2019-12-04 09:31:45

You can;

var base = window.alert;
window.alert = function(message) {
    document.getElementById("myalertwidget").innerHTML = message;
    return base.apply(this, arguments);
};

There 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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!