This is probably a stupid question, so please stick with me.
Why do I see so many examples testing whether an object is a Function by comparing its toString() to "[object Function]"?
For example:
function isFunction(obj) {
return Object.prototype.toString.call(obj) == "[object Function]";
}
Can't we use instanceof Function
or obj.constructor === Function
? Are those not cross-browser compatible?
This seems inefficient, but is it? Why?