Last active
October 24, 2018 15:42
-
-
Save loburets/e6b2194a437813a5ad73832a74210021 to your computer and use it in GitHub Desktop.
ES5 js multiple inheritance example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Machine() { | |
this._enabled = false; | |
this.enable = function() { | |
this._enabled = true; | |
}; | |
this.disable = function() { | |
this._enabled = false; | |
}; | |
} | |
function Shape() { | |
var type = '3d'; | |
this.getType = function() { | |
return type; | |
}; | |
} | |
function CoffeeMachine(power) { | |
// call the constructor functions with current context | |
// all actions of the constructors will be applied for CoffeeMachine this | |
Machine.call(this); | |
Shape.call(this); | |
this.name = "Brown"; | |
} | |
cf = new CoffeeMachine(1); | |
console.log(cf.type); // undefined | |
console.log(cf.getType()); // 3d | |
cf.enable(); | |
console.log(cf._enabled); // true | |
console.log(cf.name); // brown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment