var test = 3; // 这种其实创建的是一个variable
按ECMAv3的标准来说,正常调用一个函数的话,其内部的this就是Global,所以这么写
好在ECMAv5里又有indirect eval call,这在你的另一篇中有提到过,indirect eval call永远在global下执行,所以那个时候的this就是Global了
var global = (function() { return this || (1,eval)('(this)'); }());
再随后global.tes = 3;就安全了
test = 3; // 这种其实是在global下创建一个property
所以比较正统的符合ECMA的应该是Global.test = 3;
按ECMAv3的标准来说,正常调用一个函数的话,其内部的this就是Global,所以这么写
var global = (function() { return this; }());
好在ECMAv5里又有indirect eval call,这在你的另一篇中有提到过,indirect eval call永远在global下执行,所以那个时候的this就是Global了
var global = (1,eval)('(this)');
var global = (function() { return this || (1,eval)('(this)'); }());
再随后global.tes = 3;就安全了