Skip to content

Instantly share code, notes, and snippets.

@trivektor
Created June 7, 2013 06:13
Show Gist options
  • Select an option

  • Save trivektor/5727352 to your computer and use it in GitHub Desktop.

Select an option

Save trivektor/5727352 to your computer and use it in GitHub Desktop.
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