class - How to -separately- add functions to classes in Javascript -


this question has answer here:

i have single file looks this:

cars.js:

class cars {      saab(){         return 'saab';     }      volvo(){         return 'volvo';     }  }  var cars = new cars(); 

now want separate them in files organise code:

saab.js

class cars {     saab(){         return 'saab';     } } 

volvo.js

class cars {     volvo(){         return 'volvo';     } } 

cars.js

/**  * magic  */ var cars = new cars(); // contains function volvo() , saab() 

how can this?

ps:
problem extends (class saab extends cars) need call new saab() or new volvo() , that's not want, want call new cars().

kind of odd approach way pull off pre-es6 techniques. namely, extending prototype.

// volvo.js cars.prototype.volvo = function() {   return 'volvo'; };  // saab.js cars.prototype.saab = function() {   return 'saab'; }; 

technically, happens "under hood" class syntax. how has done if don't set of methods in class declaration.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -