Are there any significant reasons for using
typeof variable === \'function\'
versus
!!variable.call
for d
jQuery's isFunction avoids the RegExp problem you mention by toString-ing the object and checking the result against a map of known types. From the latest source, here's the map:
// Populate the class2type map
jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
class2type[ "[object " + name + "]" ] = name.toLowerCase();
});
And here's how it's used:
type: function( obj ) {
return obj == null ?
String( obj ) :
class2type[ toString.call(obj) ] || "object";
},
// See test/unit/core.js for details concerning isFunction.
// Since version 1.3, DOM methods and functions like alert
// aren't supported. They return false on IE (#2968).
isFunction: function( obj ) {
return jQuery.type(obj) === "function";
},
You can learn a lot reading the jQuery source.