Skip to content

Instantly share code, notes, and snippets.

@stefbowerman
Last active February 24, 2016 21:23
Show Gist options
  • Select an option

  • Save stefbowerman/302a01b66522ff5885f3 to your computer and use it in GitHub Desktop.

Select an option

Save stefbowerman/302a01b66522ff5885f3 to your computer and use it in GitHub Desktop.
// Option 1
$(body).on('click', function(){
console.log(this); // body
});
// Option 2
function onClick(){
console.log(this);
}
$(body).on('click', onClick.bind($(body));
// Option 3/3.5
function onClick2(element){
console.log(element);
}
// These do the same thing
$(body).on('click', onClick2.bind(this, $(body)));
$(body).on('click', function(){
onClick2($(this));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment