Skip to content

Instantly share code, notes, and snippets.

@HzJavier
Created September 10, 2015 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HzJavier/2e0c771290d01b8a4877 to your computer and use it in GitHub Desktop.
Save HzJavier/2e0c771290d01b8a4877 to your computer and use it in GitHub Desktop.
Trying to figure out which approach is better or cleaner or recommended.
/**
* Assume jQuery.
*
* Which approach is better?
*/
this.someClass = 'some-class';
// Save the scope for later use
var that = this;
this.$el.find('.some-selector').slideDown(400, function () {
that.$el.addClass(that.someClass);
});
// Use apply for the scope
this.$el.find('.some-selector').slideDown(400, function () {
this.$el.addClass(this.someClass);
}.apply(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment