Created
September 10, 2015 21:02
-
-
Save HzJavier/2e0c771290d01b8a4877 to your computer and use it in GitHub Desktop.
Trying to figure out which approach is better or cleaner or recommended.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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