Created
April 17, 2022 07:12
-
-
Save hoyangtsai/a26ad144451b372e7cf51390643b19d6 to your computer and use it in GitHub Desktop.
#js instanceof check
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 Product(name, price) { | |
this.name = name; | |
this.price = price; | |
} | |
function Food(name, price) { | |
Product.call(this, name, price); | |
this.category = 'food'; | |
} | |
const cheese = new Food('cheese', 12); | |
console.log(cheese instanceof Product) // false | |
console.log(cheese instanceof Food) // true | |
// ---- | |
console.log(123 instanceof Number) // false | |
console.log(new Number(123) instanceof Number) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment