Created
January 29, 2013 21:10
-
-
Save yangsu/4667899 to your computer and use it in GitHub Desktop.
JavaScript Function Invocation - Apply/Call
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
var incrementer = function (inc) { | |
inc = inc || 1; | |
this.value += inc; | |
}; | |
var foo = { value: 5 }; | |
incrementer.apply(foo, [1]); // foo.value = 6 | |
incrementer.call(foo, 2); // foo.value = 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment