throw Error('msg') vs throw new Error('msg')

后端 未结 2 1688
庸人自扰
庸人自扰 2020-11-28 04:56
var err1 = Error(\'message\');
var err2 = new Error(\'message\');

What\'s the difference? Looking at them in the chrome console, they look identica

2条回答
  •  无人及你
    2020-11-28 05:22

    Both are fine; this is explicitly stated in the specification:

    ... Thus the function call Error(…) is equivalent to the object creation expression new Error(…) with the same arguments.

提交回复
热议问题