我想知道当我使用andObject.defineProperty()
方法时,为什么在 catch 块内没有引发错误?get()
set()
try {
var f;
Object.defineProperty(window, 'a', {
get: function() {
return fxxxxx; // here: undef var but no error catched
},
set: function(v) {
f = v;
}
});
} catch (e) {
console.log('try...catch OK: ', e);
}
a = function() {
return true;
}
window.a();
// Expected output: "try...catch OK: ReferenceError: fxxxxx is not defined"
// Console output: "ReferenceError: fxxxxx is not defined"