是否可以访问参数名称字符串?!
function myFunction (a, b, c, d, e, f) {
var obj = [];
[].forEach.call(arguments, function(arg) {
obj.push({
// question is how to get variable name here?
name: "a",// "a", "b", "c", "d", "e", "f"
value: arg, //a, b, c, ,d, e, f
})
});
return obj;
}
myFunction(1,2,3,4,5,6); // return [{name: "a", value: 1}, {name: "b", value: 2}...]
注意:我知道使用arguments
不是一个好习惯。我想知道这是否可能?