How can “new new Something” produce valid results in JavaScript?

前端 未结 3 2071
无人共我
无人共我 2021-01-12 21:30

I\'m currently developing a JavaScript parser and study the ECMAScript 5.1 specification. Here\'s a question which puzzles me at the moment.

§ 11.2 Left-Hand

3条回答
  •  既然无缘
    2021-01-12 21:58

    It is not common at all, but it is possible; a function that returns a function:

    function baz(){}
    function foo(){return baz}
    
    new new foo() instanceof baz // true
    

提交回复
热议问题