Reputation: 312
What is more efficient in jquery:
if ($.isFunction(func_name)
$.apply(func_name, [param, etc])
or
if ($.isFunction(func_name)
func_name(param, etc)
What are the advantages to call $.apply() or $.call() over calling directly the object if it is a function as a callback.
Thanks
Upvotes: 1
Views: 4592
Reputation: 10409
Unless you're manipulating contexts, there's no reason to use call
or apply
or the equivalent jQuery helpers.
Also, you don't need to use jQuery to test if a function exists.
function foo() { alert('foo') }
if (foo && typeof foo === 'function') {
foo();
}
Upvotes: 3