Are there any significant reasons for using
typeof variable === 'function'
versus
!!variable.call
for detecting if a variable is a function?
Other than the obvious one that someone may create an object like:
{ call: 1 }
The problem that I have is that
typeof /regex/ === 'function'
returns true, but
!!/regex/.call
returns false
The safest way is to check the internal [[Class]] property by setting the object as the thisArg argument of the
.call()method when callingObject.prototype.toString.Of course you could easily make a function out of it:
This is very simple, and there could be some improvements, but you get the idea.