how to disabled alert function in javascript
alert 阻塞主线程
default
alert;
// ƒ alert() { [native code] }
alert(`1`);
OK
alert(`1`);
// alert: 1
// true
alert;
// ƒ (n){try{console.log("alert: "+n)}catch(t){}return!0}
window.alert = function(n){
try{
console.log("alert: "+n)
} catch(e){
// ignore
}
return !0;
}
!0 === true;
// true
customize alert
window.alert = function(n){
try{
console.log("alert =", n)
} catch(e){
// ignore
}
return `this is a changed alert!`;
}
alert(`1`);
// alert = 1
// "this is a changed alert!"
cnblogs
https://www.cnblogs.com/js/blog-common.min.js
demo
function a(){
var i=0;
function b(){
i++;
alert(i);
}
return b;
}
var c = a();
c();
// alert: 1
c();
// alert: 2
c();
// alert: 3
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!