Skip to content

Instantly share code, notes, and snippets.

@yasu
Created January 20, 2012 15:16
Show Gist options
  • Select an option

  • Save yasu/1647841 to your computer and use it in GitHub Desktop.

Select an option

Save yasu/1647841 to your computer and use it in GitHub Desktop.
How apply() and call() work
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