Home >Web Front-end >JS Tutorial >Bug fix for isFunction method in jQuery_jquery

Bug fix for isFunction method in jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 18:35:581182browse

jQuery 1.4 Source code 449 lines (core.js 431 lines), the method to determine whether it is a function is as follows (the idea comes from Douglas Crockford "The Miller Device" by ):

<code><span class="pln">isFunction</span><span class="pun"><font color="#666600">:</font></span><span class="pln"> </span><span class="kwd"><font color="#000088">function</font></span><span class="pun"><font color="#666600">(</font></span><span class="pln"> obj </span><span class="pun"><font color="#666600">)</font></span><span class="pln"> </span><span class="pun"><font color="#666600">{</font></span><span class="pln"><br>    </span><span class="kwd"><font color="#000088">return</font></span><span class="pln"> </span><span class="kwd"><font color="#000088">toString</font></span><span class="pun"><font color="#666600">.</font></span><span class="pln">call</span><span class="pun"><font color="#666600">(</font></span><span class="pln">obj</span><span class="pun"><font color="#666600">)</font></span><span class="pln"> </span><span class="pun"><font color="#666600">===</font></span><span class="pln"> </span><span class="str"><font color="#008800">"[object Function]"</font></span><span class="pun"><font color="#666600">;</font></span><span class="pln"><br></span><span class="pun"><font color="#666600">},</font></span></code>

At the same time, the author of jQuery also made some comments:

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).

That is: this method cannot correctly identify DOM methods and some functions (such as alert methods, etc.) under IE.

Why is this happening?


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn