Created
June 7, 2013 06:13
-
-
Save trivektor/5727352 to your computer and use it in GitHub Desktop.
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 myFunction (a, blabla, c, somethingElse, e, f) { | |
| var obj = []; | |
| //'(a, b, c, d, e, f)' | |
| var tmp = arguments.callee.toString().match(/\(.*?\)/g)[0]; | |
| //["a", "b", "c", "d", "e", "f"] | |
| var argumentNames = tmp.replace(/[()\s]/g,'').split(','); | |
| [].splice.call(arguments,0).forEach(function(arg,i) { | |
| obj.push({ | |
| // question is how to get variable name here? | |
| name: argumentNames[i],// "a", "b", "c", "d", "e", "f" | |
| value: arg, //a, b, c, ,d, e, f | |
| }) | |
| }); | |
| return obj; | |
| } | |
| console.log(JSON.stringify(myFunction(1, 2, 3, 4, 5, 6))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment