Home > Web Front-end > JS Tutorial > body text

Bug fix for isFunction method in jQuery_jquery

WBOY
Release: 2016-05-16 18:35:58
Original
1139 people have browsed it

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>
Copy after login

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?


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template