Why jQuery.isFunction?

Usually you can test whether JS object is function by using this test:
(typeof fn === 'function')

However, this doesn't always work (IE8):

typeof alert => 'object'
typeof document.createElement('input').getAttribute => 'object'

Before jQuery 1.4 internally they used the same check, but now they've fixed it. So to be sure that passed object is a function which can be called, just use $.isFunction method:

$.isFunction(function() {}) => true
$.isFunction(alert) => true
$.isFunction(document.createElement('input').getAttribute) => true


Popular posts from this blog

DIY: Business cards in LaTeX

Python vs JS vs PHP for embedded systems

Web application framework comparison by memory consumption