Skip to content

Instantly share code, notes, and snippets.

@getdave
Created May 16, 2017 12:50
Show Gist options
  • Save getdave/19cd9969d6ff9145073b5a16972527b5 to your computer and use it in GitHub Desktop.
Save getdave/19cd9969d6ff9145073b5a16972527b5 to your computer and use it in GitHub Desktop.
Example of Classical Inheritance
class Appliance {
turnOn() {
console.log(this.type + " now online");
}
}
class Oven extends Appliance {
constructor() {
this.type = "Oven";
}
setTemperature(temp) {
console.log("Temp set to ${temp}");
}
}
class Radio extends Appliance {
constructor() {
this.type = "Radio";
}
setChannel(channel) {
console.log("Now listening to channel ${temp}");
}
}
$oven_1 = new Oven();
// Inherited functionality
$oven_1->turnOn(); // --> "Oven now online"
$oven_1->setTemperature(100); // --> "Temp set to 100"
$radio = new Radio();
// Inherited functionality
$radio->turnOn() // --> "Radio now online"
$radio->setChannel(5); // --> "Now listening to channel 5"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment