Last active
November 1, 2017 18:18
-
-
Save thiagoh/9bea93b09b8352584198f97e161f67a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 MyClass { | |
static [Symbol.hasInstance](lho) { | |
console.log('with-sugar: is', lho, 'an array?'); | |
return Array.isArray(lho); | |
} | |
} | |
console.log([] instanceof MyClass); // true | |
console.log('my string' instanceof MyClass); // false |
This file contains hidden or 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
const MyClass = function() {}; | |
Object.defineProperty(MyClass.prototype.constructor, Symbol.hasInstance, { | |
value: function(lho) { | |
console.log('without-sugar: is', lho, 'an array?'); | |
return Array.isArray(lho); | |
} | |
}); | |
console.log([] instanceof MyClass); // true | |
console.log('my string' instanceof MyClass); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment