Created
March 22, 2018 15:20
-
-
Save flipjs/f7172d5ff5ca81b695629d8e11dde6fa to your computer and use it in GitHub Desktop.
instanceof demo
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
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