Created
September 23, 2012 14:40
-
-
Save zhuzhuaicoding/3771675 to your computer and use it in GitHub Desktop.
this gist aim at illustrating the arguments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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