• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XenForo.context vs function .bind

Uniphix

Active member
#1
What is the difference the $.context (extended from jQuery via XenForo) function works like the function bind?

for example...


$('#element').click($.context(this, 'elementClick'));

I can see that it would work best this above if your trying to reference a function.

$('#element').click(function(e){
this.elementClick(e);
}.bind(this));

or

$('#element').click(this.elementClick.bind(this)); which is the same thing as $.context(this, 'elementClick');

$('#element').click($.context(function(){
alert('Hello World');
}, this));

What is the purpose of the two functions?