問題:
I have seen objects being created this way:我見過以這種方式創建的對象:
const obj = new Foo;
But I thought that the parentheses are not optional when creating an object:但是我認爲在創建對象時括號不是可選的:
const obj = new Foo();
Is the former way of creating objects valid and defined in the ECMAScript standard?前一種創建對象的方式是否有效並在 ECMAScript 標準中定義? Are there any differences between the former way of creating objects and the later?前者和後者創建對象的方式有什麼區別嗎? Is one preferred over the other?一個比另一個更受歡迎嗎?
解決方案:
參考一: https://en.stackoom.com/question/CjWf參考二: https://stackoom.com/question/CjWf