ES6 Javascript Classes - define class method to an existing function -
this question has answer here:
in es5 can setting prototype existing function how go es6 classes
//// es5 function existingfn = function () { // }; function myclass () { // constructor stuff }; myclass.prototype.newfn = function () { // … }; myclass.prototype.existingfn = existingfn; //// es6 class myclass { constructor() {} newfn() { // … } // ??????? // existingfn = existingfn // ??????? }
ecma-script 6 class syntax syntactic sugar on regular prototype system:
class { } // still possible! a.prototype.dostuff = function() { }; var existingfn = function() {}; a.prototype.existingfn = existingfn; var instance = new a(); instance.existingfn();
Comments
Post a Comment