Skip to content

Instantly share code, notes, and snippets.

@flipjs
Created March 22, 2018 15:20
Show Gist options
  • Save flipjs/f7172d5ff5ca81b695629d8e11dde6fa to your computer and use it in GitHub Desktop.
Save flipjs/f7172d5ff5ca81b695629d8e11dde6fa to your computer and use it in GitHub Desktop.
instanceof demo
class Person {
constructor(name) {
this.name = name;
}
}
class Worker extends Person {
constructor(name, profession) {
super(name);
this.profession = profession;
}
}
const person = new Person('Chris');
const worker = new Worker('Adam', 'Teacher');
console.log('person is an instance of Person?', person instanceof Person);
console.log('person is an instance of Worker?', person instanceof Worker);
console.log('worker is an instance of Person?', worker instanceof Person);
console.log('worker is an instance of Worker?', worker instanceof Worker);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment