Monday, May 20, 2024
110
rated 0 times [  112] [ 2]  / answers: 1 / hits: 29681  / 9 Years ago, sun, march 8, 2015, 12:00:00

In the ES6, if I make a class and create an object of that class, how do I check that the object is that class?



I can't just use typeof because the objects are still object. Do I just compare constructors?



Example:



class Person {
constructor() {}
}

var person = new Person();

if ( /* what do I put here to check if person is a Person? */ ) {
// do stuff
}

More From » ecmascript-6

 Answers
56

Can't you do person instanceof Person?



Comparing constructors alone won't work for subclasses


[#67530] Thursday, March 5, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
donaldcristianl

Total Points: 114
Total Questions: 95
Total Answers: 110

Location: Bonaire
Member since Sat, May 27, 2023
1 Year ago
;