ecmascript 6 - Is ES6 class extend fully equivalent to Object.assign based extending of an object? -
ecmascript 6 - Is ES6 class extend fully equivalent to Object.assign based extending of an object? -
in other words these 2 different blocks of code equivalent?
es6 class extend basedclass kid extends parent { // define subclass } var myinstance = new child();
object.assign based var myinstance = object.assign(new parent(), { // define subclass }
in particular utilize case trying extend (facebook's) flux dispatcher. in examples utilize object.assign. es6 class extend, worried there subtle differences between 2 should stick object.assign.
no, code blocks not equivalent
in class inheritance new constructor makes objects having features parent class.
extending objects via object.assign
illustration of mixins. add together properties 1 instance not alter future children.
unlike kid classes, instance after extension still have constructor
property pointing parent
. means can't recognize extended kid among non-extended, because have same constructor , operator instanceof
give same result. can't access overridden methods in child, because lose link it.
as flux's dispatcher in example, can't extend via class inheritance, because there not constructor can provide parent.
ecmascript-6
Comments
Post a Comment