One simple approach used in libraries such as trunk:
typeof o === type;
ES5 suggests using something similar to
(Object.prototype.toString.call(o) === '[object ' + type + ']');
and finally, SO users shared: ( getType code overview )
o.constructor === type;
Here are three fundamentally different ways.
- using typeof
- using toString
- using constructor property
I would like to use these 3 methods to write a generic checkType method.
Any advice on how to best combine them logically or why is there can be in many ways.
user1637281
source share