angularjs - automatic class binding of es6 spread operator to constructor -
i'm working angular, jspm, , es6. i'm working base class inject dependencies onto constructor , automatically register on 'this'.
this pattern exists in react when extend base component class. found guy's little shortcut method here: http://www.newmediacampaigns.com/blog/refactoring-react-components-to-es6-classes
i looking way angular, using es6 classes bind injected dependencies constructor's "this".
class baseclass { constructor(...injections) { this._bind(injections) } _bind(injections) { injections.foreach( (injection) => { this[injection.name] = injection; }); } } class diclass extends baseclass { constructor($q, someangularfactory) { super($q, someangularfactory); } }
this doesn't work (injection.name not thing, know)... does. question how "name" of injected function or object. in example, _bind function gives raw object or function... don't know how "$q" or "someangularfactory" string.
you can kind of using "object.getownpropertynames(...injections)", not inside _bind function.
thanks feedback or ideas have.
you this:
class baseclass { constructor(injections) { object.assign(this, injections); } } class diclass extends baseclass { constructor($q, someangularfactory) { super({ $q, someangularfactory }); } }
obs.: classes, object.assign es2015 feature , merges second (parameter) object first one.
Comments
Post a Comment