3 ms·
no, Object.create() creates the object and sets __proto__ but it does not call the function. "new" also calls the function.
by lucio 13y ago
no, Object.create() creates the object and sets __proto__ but it does not call the function. "new" also calls the function.
- Kiro 13y agoThanks. Would an empty Superclass constructor result in the same thing?
- shawnz 13y agoThat's correct. If the Superclass constructor had code in it, then that code would only be run once, regardless of the number of Subclass objects created. So, they would effectively share their super implementations, as if they were just one object. This doesn't matter when the super constructor doesn't do anything, since there is no difference. The Object.create pattern avoids this by not calling the super constructor at all. If you need the super constructor to be called the way it is in classical inheritance, then you can call Superclass.call(this) in the Subclass constructor along with using Object.create. More details: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create#Classical_inheritance_with_Object.create https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- deleted 13y ago[deleted]