Created
February 24, 2023 06:18
-
-
Save AnshKapoor/97db81c4cec722335aee393311e38b0b to your computer and use it in GitHub Desktop.
Changing behavior of instanceOf in Javascript
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 MyArray { | |
static [Symbol.hasInstance](instance) { | |
return Array.isArray(instance); | |
} | |
} | |
const arr = [1, 2, 3]; | |
console.log(arr instanceof MyArray); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment