javascript - Can you alter an ES6 class definition to attach new instance methods? -


is there way retroactively (i.e. after class has been defined) add instance methods es6 class?

consider following class:

class thing {} 

i'd attach hello method thing, callable on instances so:

let thing = new thing(); thing.hello(); 

is possible?

(sure, make subclass, that's not i'm asking here.)

or use object.assign

object.assign(thing.prototype, {     hello(arg1, arg2) {         // magic goes here     } }); 

this equivalent

thing.prototype.hello = function (arg1, arg2) {     // magic goes here }; 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -