Using “Object.create” instead of “new”

后端 未结 15 2366
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 06:08

Javascript 1.9.3 / ECMAScript 5 introduces Object.create, which Douglas Crockford amongst others has been advocating for a long time. How do I replace new

15条回答
  •  一个人的身影
    2020-11-22 07:11

    While Douglas Crockford used to be a zealous advocate of Object.create() and he is basically the reason why this construct actually is in javascript, he no longer has this opinion.

    He stopped using Object.create, because he stopped using this keyword altogether as it causes too much trouble. For example, if you are not careful it can easily point to the global object, which can have really bad consequences. And he claims that without using this Object.create does not make sense anymore.

    You can check this video from 2014 where he talks at Nordic.js:

    https://www.youtube.com/watch?v=PSGEjv3Tqo0

提交回复
热议问题