Created
September 12, 2012 14:53
-
-
Save Incognito/3707161 to your computer and use it in GitHub Desktop.
Forwarding arguments of variadic function calls.
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
| function q(){ | |
| console.log(arguments.length + " from q"); | |
| var b = function(){ | |
| console.log(arguments.length + " from b"); | |
| } | |
| b.apply(this, arguments); | |
| } | |
| q(); //0 from q, 0 from b | |
| q(1); //1 from q, 1 from b | |
| q(1, 2); //2 from q, 2 from b | |
| q(1, 2, 3, 1); //4 from q, 4 from b | |
| |
Also, your use of this will point to the global object in non-strict mode code and undefined in strict mode code if new is omitted. I would just pass null for thisArg.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are missing a semicolon in the variable declaration. Also, you should move that declaration to the top (i.e.
var b;) to reduce confusion.