ECMAScript 6 (Harmony) introduces classes
with ability to inherit one from another. Suppose I have a game and some basic class to describe basic things for bot
The following code will do what you want, though it is currently only supported in FF 41+ and Chrome 47+ (see https://kangax.github.io/compat-table/es6/)
class Bot{
constructor(){
if (new.target === Bot)
this.render();
}
render(){
console.log('Bot rendered');
}
}
class DevilBot extends Bot{
constructor(){
super();
this.color = 0xB4D333;
this.render();
}
render(){
console.log('DevilBot rendered with', this.color);
}
}
var bot = new Bot(); // Bot rendered
var dev = new DevilBot(); // DevilBot rendered with 11850547