Created
January 20, 2012 15:16
-
-
Save yasu/1647841 to your computer and use it in GitHub Desktop.
How apply() and call() work
This file contains hidden or 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
| function makeArray(arg1, arg2){ | |
| return [ this, arg1, arg2 ]; | |
| } | |
| var gasGuzzler = { year: 2008, model: 'Dodge Bailout' }; | |
| makeArray.apply( gasGuzzler, [ 'one', 'two' ] ); | |
| // => [ gasGuzzler, 'one' , 'two' ] | |
| makeArray.call( gasGuzzler, 'one', 'two' ); | |
| // => [ gasGuzzler, 'one' , 'two' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment