What is the difference between `new Object()` and object literal notation?

前端 未结 11 805
北恋
北恋 2020-11-22 07:41

What is the difference between this constructor-based syntax for creating an object:

person = new Object()

...and this literal syntax:

11条回答
  •  一生所求
    2020-11-22 08:26

    The only time i will use the 'new' keyowrd for object initialization is in inline arrow function:

    () => new Object({ key: value})
    

    since the below code is not valid:

    () => { key: value} //  instead of () => { return { key: value};}
    

提交回复
热议问题