如何禁用页面上的某些警报并允许其他人?
我尝试使用此代码:
window.alert = function ( text ) {
console.log(text);
if(!text.includes("rambo"))
alert("rambo");
};
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为它再次调用警报而不是警报.
我需要使用javascript警报(不是任何其他库)
我需要更改不可扩展的对象。有什么办法可以改变这个对象属性吗?
我已经阅读了文档,它说“一旦对象不可扩展,就无法再次使对象可扩展。”
有什么解决方法吗?比如复制对象什么的?
function trycatch(myfunction, name) {
return function() {
try {
myfunction.apply(this, arguments);
} catch (e) {
console.log(e + name);
}
}
};
var rambo = {
create: function(i, j) {
return i
},
ramv: function() {
aler("")
}
};
for (var key in rambo) {
if (typeof rambo[key] === 'function') {
rambo[key] = trycatch(rambo[key], key);
}
}
console.log(rambo.create(1))Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>Run Code Online (Sandbox Code Playgroud)
我试图将try catch应用到我的所有函数中,但似乎它们没有返回值,我错过了什么?