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

前端 未结 11 780
北恋
北恋 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:35

    Also, according to some of the O'Really javascript books....(quoted)

    Another reason for using literals as opposed to the Object constructor is that there is no scope resolution. Because it’s possible that you have created a local constructor with the same name, the interpreter needs to look up the scope chain from the place you are calling Object() all the way up until it finds the global Object constructor.

提交回复
热议问题