3 ms·
No- static isDog (animal) { return Object.getPrototypeOf(animal).constructor.name === this.name; } Yes- static isDog (animal) { r
by randomfool 8y ago
No-
static isDog (animal) {
return Object.getPrototypeOf(animal).constructor.name === this.name;
}
Yes-
static isDog (animal) {
return animal instanceof Dog;
}
- chrismorgan 8y agoOr, if you want to check “is a Dog and not an instance of some subtype of it”: static isDog (animal) { return Object.getPrototypeOf(animal).constructor === this; } Definitely no need for the `.name` check—that weakens it enormously, especially in the presence of minification.