Understanding Crockford's Object.create shim

后端 未结 5 1526
后悔当初
后悔当初 2020-11-28 14:44

I\'ve been reading up on the Crockford shim for preventing the overwriting of prototypes, and understand that it\'s not the end-all/be-all solution at times. I also underst

5条回答
  •  情书的邮戳
    2020-11-28 15:16

    All it does is create a new object constructor, which is F, it then assign the passed object to the constructor prototype property so that new object created with the F constructor inherit those methods.

    It then use the constructor to return an newly initialize object (new F() => F.prototype)

    But the crockford one fail to reassign the constructor properly as normally the new object constructor should be the same as the object constructor it inherits from.

提交回复
热议问题