Skip to content

Instantly share code, notes, and snippets.

@shahab570
Created January 7, 2021 14:18
Show Gist options
  • Save shahab570/1d57c17ab076d765654e080e8826a77d to your computer and use it in GitHub Desktop.
Save shahab570/1d57c17ab076d765654e080e8826a77d to your computer and use it in GitHub Desktop.
class Person {
constructor(name) {
this.name = name;
}
sayHi() {
console.log("Hi I am", this.name, " I am a human");
}
}
class Robot extends Person {
constructor(name) {
super(name);
}
sayHi() {
console.log("Hi I am", this.name, " I am a robot");
}
}
let person = new Person("John smith");
let sofia = new Robot("SOFIA");
person.sayHi(); //Hi I am john smith, I am a human
sofia.sayHi(); //Hi I am SOFIA , I am a robot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment