有没有办法动态获取函数的函数参数名称?
假设我的函数看起来像这样:
function doSomething(param1, param2, .... paramN){
// fill an array with the parameter name and value
// some other code
}
Run Code Online (Sandbox Code Playgroud)
现在,我如何从函数内部获取参数名称及其值的列表到数组中?
我有这段代码:
function MyFunction()
{
$.ajax({
type: "POST",
url: "ajax.php",
dataType: "json",
data: "foo=bar",
error:function(XMLHttpRequest, textStatus, errorThrown)
{
alert(arguments.callee);
},
success: function(jsonObject)
{
//do something
}
});
}
Run Code Online (Sandbox Code Playgroud)
我想要的是de error scoope里面的警告显示了函数名,在本例中是"MyFunction",而是我得到的是错误:function.
我怎样才能做到这一点?