jQuery 1.4.2 in IE 8
When I call $.isFunction(function() {})
it returns true
.
Source code isFunction
function:
isFunction: function (obj) {
return toString.call(obj) === "[object Function]";
},
When I write in console toString.call(function() {}) === "[object Function]"
it throws "Object doesn't support this property or method"
.
Source code of minified version:
isFunction:function(a){return $.call(a)==="[object Function]"}
When I write in console $.call(function() {})==="[object Function]"
it returns false
.
Why code works in different ways?
-
What are you actually asking here?Alex– Alex2011年10月14日 09:26:51 +00:00Commented Oct 14, 2011 at 9:26
2 Answers 2
At the top of the JQuery 1.4.2 source (inside the wrapper), toString
is defined as Object.prototype.toString
. The global toString
function is different from the prototyped toString
method, hencethe different results.
// Save a reference to some core methods
toString = Object.prototype.toString,
Comments
this is the truth :
alert( Object.prototype.toString.apply(t) );