使用返回javascript函数的新运算符返回奇数范围

使用返回javascript函数的新运算符返回奇数范围,javascript,new-operator,Javascript,New Operator,我试图理解为什么new针对函数运行,而不是示例中函数的返回y=: function returnFunction(){ return function blah(str){ this.x = str; return this;}} y = new returnFunction()("blah") // output: Window {x: "blah"; top: Window, window: Window, location: Location, ....} x = new (return

我试图理解为什么new针对函数运行,而不是示例中函数的返回
y=

function returnFunction(){ return function blah(str){ this.x = str; return this;}}

y = new returnFunction()("blah")
// output: Window {x: "blah"; top: Window, window: Window, location: Location, ....}
x = new (returnFunction())("blah")
// output: blah {x: "blah"}

z = new function blah(){return this;}()
// output: blah {}

zz = new function(){return this;}() //note the missing function name
// output: Object {}

b = new function blib(str){this.x = str; return this}
// blib {x: undefined}
bb = new function blib(str){this.x = str; return this}("blah")
// blib {x: "blah"}
c = new function blib(){this.x = "blah"; return this}
// blib {x: "blah"}
因此,对于y new,创建一个
returnFunction
的副本,然后调用它

y = (new returnFunction())()
通过调用匿名函数,我们没有
这个
,因此它默认为
窗口

x
的情况下,通过将其包装在参数中(
returnFunction
被调用,返回
blah
函数),然后
blah
被新的操作符设置
this
调用到新对象

奇怪的是,我必须包装
new(returnFunction())
以使其按正确的顺序执行


有人能给我解释一下底层执行吗?

new
的优先级高于调用参数
()
。请参阅。

这只是因为运算符优先级<代码>新建的优先级高于函数调用。将函数调用包装在括号中会更改求值顺序

有关详细信息,请参阅MDN上的优先级表: