2014-04-08 100 views
0

匿名函数当运行这个片段参数在严格模式

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

为什么我得到undefineda?为什么窗口没有传递给匿名函数?

+0

'新功能...'返回一个对象,而不是一个函数 –

回答

1

你在做什么(几乎)等价于:

"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);