我正在阅读有关 JavaScript 中 OO 编程的书,并得到一些奇怪的行为:
function f1() {
var a = 1;
console.log('a in f1 function ', a);
console.log('f2() called ', f2());
return 'f1 return value';
}
function f2() {
console.log('a value in f2() ', a);
return a;
}
var a = 5;
a = 55;
var foo = 'bar';
console.log('delete a: ', delete a);
console.log(a);
console.log(f1());
console.log('delete window.f2: ', delete window.f2);
console.log(f1());
console.log('delete foo: ', delete foo);
谁能理解,为什么我的 delete VARIABLE 返回 false(在 Firefox 中)和严格模式显示警告,如:
SyntaxError: applying the 'delete' operator to an unqualified name is deprecated
console.log('delete foo: ', delete foo);