Is calling a function that returns a function with new different than just invoking it normally?

前端 未结 3 1758
南旧
南旧 2021-01-21 21:51

So let\'s say I have a javascript function

function A(){
    return function(){
        console.log(\'something\');
        return new B();
    }
}
3条回答
  •  有刺的猬
    2021-01-21 22:01

    When you call the function without "new", what is it that you suspect "this" is pointing to? It'll be "window." Updating that is slower than updating the freshly-built new object you'll be using when you invoke it with "new".

提交回复
热议问题