Why use {} instead of new Object() and use [] instead of new Array() and true/false instead of new Boolean()?

后端 未结 5 1102
南方客
南方客 2020-12-06 00:55

Many people say that you should avoid new Object, new Array()and instead use {}. [], and true/false.

What are the benefits of using the literal constructs to get a

5条回答
  •  情深已故
    2020-12-06 02:00

    In most cases an object literal or array literal is sufficient and easier to use. You can even call or apply prototype methods (e.g. [].prototype.slice.call(someObj)) It's mostly faster too. You'll may want to notice that {} and []‘s constructor cannot be overwritten and that Object and Array are constructors where {} and [] are instances.

提交回复
热议问题