Creating JS object with Object.create(null)?

前端 未结 5 494
不知归路
不知归路 2020-11-28 01:58

I know a lot of ways to create JS objects but I didn\'t know the Object.create(null)\'s one.

Question:

is it exactly the same as:

5条回答
  •  离开以前
    2020-11-28 02:34

    When you create an Object with Object.create(null) that means you are creating an Object with no prototype.null here means end of prototype chain. Nevertheless when you create an object like {} Object prototype will be added. Hence these are two different objects, one with prototype another without prototype.Hope this helps

提交回复
热议问题