我已经探索了 getter/setter 的工作原理......
document.body.innerHTML = 'This will change the site';
Object.defineProperty(document.body, 'innerHTML', {
get: function(){
console.log('[FAKED] document.innerHTML');
return false;
},
set: function(val){
console.log('[FAKED] document.innerHTML = '+val);
return false;
}
});
alert(document.body.innerHTML); // false
如果浏览器不支持innerHTML,或者您想为 <progress>
制作一个好的 pollyfill,这可能是一件好事。 。但是,如果您愚蠢到执行此代码。怎么才能恢复到原来的样子呢?
最佳答案
您破坏了 .innerHTML
的浏览器定义。
没有回头路了...
关于javascript - 恢复 native setter/getter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10474575/