Skip to content

Instantly share code, notes, and snippets.

@thiagoh
Last active November 1, 2017 18:18
Show Gist options
  • Save thiagoh/9bea93b09b8352584198f97e161f67a8 to your computer and use it in GitHub Desktop.
Save thiagoh/9bea93b09b8352584198f97e161f67a8 to your computer and use it in GitHub Desktop.
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
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