jQuery 1.4 源码 449 行(core.js 431 行),判断是否为函数的方法如下(思路来源于 Douglas Crockford 的《The Miller Device》):
<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>同时 jQuery 的作者也作了部分注释:
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).
即:此方法在 IE 下无法正确识别 DOM 方法和一些函数(例如 alert 方法等)。
为什么会这样呢?
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号