Skip to content

Instantly share code, notes, and snippets.

@AnshKapoor
Created February 24, 2023 06:18
Show Gist options
  • Save AnshKapoor/97db81c4cec722335aee393311e38b0b to your computer and use it in GitHub Desktop.
Save AnshKapoor/97db81c4cec722335aee393311e38b0b to your computer and use it in GitHub Desktop.
Changing behavior of instanceOf in Javascript
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