Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
189
rated 0 times [  190] [ 1]  / answers: 1 / hits: 19647  / 12 Years ago, thu, august 30, 2012, 12:00:00

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?


More From » jquery

 Answers
80

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.


[#83322] Wednesday, August 29, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mathewb

Total Points: 535
Total Questions: 95
Total Answers: 96

Location: British Indian Ocean Territory
Member since Fri, Oct 15, 2021
3 Years ago
;