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
Post a Comment