Skip to content

Instantly share code, notes, and snippets.

@zhuzhuaicoding
Created September 23, 2012 14:40
Show Gist options
  • Select an option

  • Save zhuzhuaicoding/3771675 to your computer and use it in GitHub Desktop.

Select an option

Save zhuzhuaicoding/3771675 to your computer and use it in GitHub Desktop.
this gist aim at illustrating the arguments.
var what_the_arguments_refer_to = function(fn) {
return function() { // arguments -> this function
//debugger;
var args = Array.prototype.slice.call(arguments);
return fn.apply(null, [1].concat(args));
};
};
var console_log_closures = function(a, b, c) {
return console.log(a, b, c);
}
what_the_arguments_refer_to(console_log_closures)(3, 4);//1,3,4
So:the arguments in inner closures is refer to the inner anonymous function.
var doParallel = function(fn) {
return function() { // arguments -> this function
//debugger;
var args = Array.prototype.slice.call(arguments);
return fn.apply(null, [1].concat(args));
};
};
var f = function(a, b, c) {
return console.log(a, b, c);
}
doParallel(f)(3, 4);//1,3,4
So:the arguments in inner closures is refer to the inner anonymous function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment