Created
January 29, 2013 21:09
-
-
Save yangsu/4667889 to your computer and use it in GitHub Desktop.
JavaScript Function Invocation - Function Invotation
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
// this refers to the global object (a mistake in the language design) | |
obj.quadruple = function () { | |
var that = this; // common idiomatic workaround for preserving context | |
var helper1 = function () { | |
that.value = that.value * 2; | |
}; | |
var helper2 = function () { | |
this.value = this.value * 2; | |
}; | |
helper1(); | |
helper2.call(this); // Alternatively, bind this when invoking | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment