[英]Parameters for anonymous function in strict mode
When running this snippet 运行此代码段时
"use strict";
(new function test(a) { console.log(a); })(window);
Why do I get undefined
for a
? 为什么我对
a
undefined
? Why isn't the window passed to the anonymous function? 为什么窗口没有传递给匿名函数?
What you're doing is (almost) equivalent to this: 您所做的(几乎)等同于此:
"use strict";
function test(a) {
console.log(a);
}
val t = new test(undefined);
t(window);
Just remove the new
keyword: 只需删除
new
关键字:
"use strict";
(function test(a) { console.log(a); })(window);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.