Skip to content

Instantly share code, notes, and snippets.

@tsterker
Created April 17, 2012 20:40
Show Gist options
  • Save tsterker/2408855 to your computer and use it in GitHub Desktop.
Save tsterker/2408855 to your computer and use it in GitHub Desktop.
[js] argument unpacking
// Taken from:
// http://readystate4.com/2008/08/17/javascript-argument-unpacking-converting-an-array-into-a-list-of-arguments/
var item1 = ['Jack', '39', 'Panda'];
function hi(name, age, type){
console.log('Hi ' + name + '! You are ' + age + ' and a ' + type + '!');
}
hi.apply(this, item1);
// Outputs to your Firebug console: Hi Jack! You are 39 and a Panda!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment