Skip to content

Instantly share code, notes, and snippets.

@jackfranklin
Created December 19, 2012 09:56
Show Gist options
  • Save jackfranklin/4335644 to your computer and use it in GitHub Desktop.
Save jackfranklin/4335644 to your computer and use it in GitHub Desktop.
var array = [1,2,3,4];
array = array.map(function(x) {
return x*x;
})
console.log("regular array", array); // [1,4,9,16]
function foo() {
array = arguments.map(function(x) {
return x*x;
});
console.log("arguments", array);
}
//foo(1,2,3,4); //error: Object #<Object> has no method 'map'
// hence why we might do:
function betterFoo() {
var args = Array.prototype.slice.call(arguments);
array = args.map(function(x) {
return x*x;
});
console.log("arguments -> array", array);
}
betterFoo(1,2,3,4); // [1,4,9,16]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment