Jonah Jonah - 1 year ago 76
jQuery Question

Why can't functions be assigned to variables and keep their functionality?

This works:

var foo = $("#bar");

This doesn't:

var foo = $("#bar").html;

What breaks the functionality?

Answer Source

Well this should:

var bar = $("#bar");
var foo = bar.html.bind(bar);

In your second example, the html function lost its calling context when you assigned it to the foo variable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download