What I want to do
I'd like to write a function that is able to deal with two different argument types as its first parameter.
To be more specific, the function shall be able to deal with the first argument either being NodeList
or Element
.
My research
I was researching a bit on how to detect the type of a variable, since I'm not using libraries like jQuery or underscore and came across a variety of resources. Those were the best:
- http://tobyho.com/2011/01/28/checking-types-in-javascript/
- How do I get the name of an object's type in JavaScript?
I didn't expect that this particular corner of JavaScript is this flawed. The resources above list ways of doing this with typeof
, instanceof
etc.
But none of the resources I've found included isPrototypeOf
as a viable option.
The question
I found NodeList.prototype.isPrototypeOf(myParam)
and Element.prototype.isPrototypeOf(myParam)
to work quite well. Since none of the resources I've found discusses the usage of isPrototypeOf
, I'm wondering:
Are there any caveats using isPrototypeOf
to check a variable for a specific type?