相关疑难解决方法(0)

如何动态获取函数参数名称/值?

有没有办法动态获取函数的函数参数名称?

假设我的函数看起来像这样:

function doSomething(param1, param2, .... paramN){
   // fill an array with the parameter name and value
   // some other code 
}
Run Code Online (Sandbox Code Playgroud)

现在,我如何从函数内部获取参数名称及其值的列表到数组中?

javascript reflection function-parameter

282
推荐指数
14
解决办法
16万
查看次数

在javascript中获取当前函数名称

我有这段代码:

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.

我怎样才能做到这一点?

jquery function

16
推荐指数
2
解决办法
1万
查看次数