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
(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
Comments
Post a Comment