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

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -