Skip to content

Instantly share code, notes, and snippets.

@taiansu
Created May 26, 2012 10:11
Show Gist options
  • Save taiansu/2793242 to your computer and use it in GitHub Desktop.
Save taiansu/2793242 to your computer and use it in GitHub Desktop.
Manipulate the arguments
f = (a, b, c...) ->
console.log "arguments: #{a}, #{b}, #{c}".replace(/, $/,"")
for arg, i in arguments
console.log "#{i}: #{arg}"
f "ruby"
#"ruby"
#"0: ruby"
f "ruby", "coffeescript"
###
"ruby","coffeescript"
"0: ruby"
"1: coffeescript"
###
f "ruby", "coffeescript", "lisp"
###
"ruby","coffeescript", "lisp"
"0: ruby"
"1: coffeescript"
"2: lisp"
###
var f = function(a, b){
var args = Array.prototype.slice.call(arguments);
console.log("arguments: " + args.join(","));
for(var i = 0; i < arguments.length; i++){
console.log(i.toString() + ": " + arguments[i]);
}
}
f("ruby");
//"ruby"
//"0: ruby"
f("ruby", "coffeescript");
/*
"ruby","coffeescript"
"0: ruby"
"1: coffeescript"
*/
f("ruby", "coffeescript", "lisp");
/*
"ruby","coffeescript", "lisp"
"0: ruby"
"1: coffeescript"
"2: lisp"
*/
var f,
__slice = [].slice;
f = function() {
var a, arg, b, c, i, _i, _len, _results;
a = arguments[0], b = arguments[1], c = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
console.log(("arguments: " + a + ", " + b + ", " + c).replace(/, $/, ""));
_results = [];
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
_results.push(console.log("" + i + ": " + arg));
}
return _results;
};
f("ruby");
f("ruby", "coffeescript");
f("ruby", "coffeescript", "lisp");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment