Javascript 严格模式下匿名函数的参数

Javascript 严格模式下匿名函数的参数,javascript,anonymous-function,strict,Javascript,Anonymous Function,Strict,运行此代码段时 "use strict"; (new function test(a) { console.log(a); })(window); 为什么对于a,我会得到未定义的?为什么没有将窗口传递给匿名函数?您所做的(几乎)与此等效: "use strict"; function test(a) { console.log(a); } val t = new test(undefined); t(window); 只需删除new关键字: "use strict"; (funct

运行此代码段时

"use strict";
(new function test(a) { console.log(a); })(window);
为什么对于
a
,我会得到
未定义的
?为什么没有将窗口传递给匿名函数?

您所做的(几乎)与此等效:

"use strict";

function test(a) {
  console.log(a);
}

val t = new test(undefined);

t(window);
只需删除
new
关键字:

"use strict";
(function test(a) { console.log(a); })(window);

新函数…
返回一个对象,而不是函数