(typeof variable ==="函数")和jQuery.isFunction()之间有什么区别? [英] What's the difference between (typeof variable === "function") and jQuery.isFunction()?

查看:258
本文介绍了(typeof variable ==="函数")和jQuery.isFunction()之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是使用(typeof variable ===function),我偶然发现 jQuery.isFunction()我想知道:


  1. typeof方法和jQuery方法有什么不同?不仅如此,而且
  2. 什么时候使用typeof方法以及什么时候使用jQuery方法是适当的?

>

解决方案

几乎没有区别,除了使用jQuery稍微慢一点。查看源代码:

  isFunction:function(obj){
return jQuery.type(obj)=== 功能;
},

调用另一个函数来确定 与您展示的内容相同:P



在这种情况下,jQuery几乎没有优势[或者对于这种情况,90%的用例图书馆]。查看 Vanilla-JS 并查看它的一些功能:P



TLDR:不要对此使用jQuery ...或任何其他内容。
$ b

UPDATE



这是一个基准,向你展示Vanilla JS比jQuery快93%: http: //jsperf.com/jquery-isfunction-vs-vanilla-is-function


I have always used (typeof variable === "function") and I stumbled across jQuery.isFunction() and I was wondering:

  1. What is the difference between the typeof method and jQuery's method? And not only what the difference is, but
  2. When is it appropriate to use the typeof method and when is it appropriate to use jQuery's method?

解决方案

There is almost no difference, other than that using jQuery is slightly slower. See the source code:

isFunction: function( obj ) {
    return jQuery.type(obj) === "function";
},

which calls a function which calls another function to determine the exact same thing as what you showed :P

There is literally no advantage to jQuery in this case [or for that manner, 90% of the use-cases of the library]. Look into Vanilla-JS and check out some of its features :P

TLDR: Don't use jQuery for this...or anything.

UPDATE

Here's a benchmark showing you that Vanilla JS is roughly 93% faster than jQuery: http://jsperf.com/jquery-isfunction-vs-vanilla-is-function.

这篇关于(typeof variable ==="函数")和jQuery.isFunction()之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆