是否有可能反映Javascript函数的参数? [英] Is it possible to reflect the arguments of a Javascript function?

查看:149
本文介绍了是否有可能反映Javascript函数的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能将Javascript函数的所有参数写入接受? (我知道所有Javascript函数参数都是可选的)?如果没有,是否可以获得参数的数量?例如,在PHP中,可以使用:

Is it possible to get all of the arguments a Javascript function is written to accept? (I know that all Javascript function arguments are "optional")? If not, is it possible to get the number of arguments? For example, in PHP, one could use:

$class = new ReflectionClass('classNameHere');
$methods = $class->getMethods();
foreach ($methods as $method) {
    print_r($method->getParameters());
}

...或类似的东西,我还没有碰过PHP虽然上面的例子可能不正确。

... or something like that, I haven't touched PHP in a while so the example above may not be correct.

提前致谢!

编辑:不幸的是,我有能够获得函数体的外部的论据...对于缺乏澄清感到抱歉,但感谢您当前的答案!

Unfortunately, I have to be able to get the arguments outside of the body of the function... Sorry for the lack of clarification, but thanks for the current answers!

推荐答案

假设您的函数名称是 foo


是否有可能获得Javascript函数的所有参数都是
写入接受?

Is it possible to get all of the arguments a Javascript function is written to accept?

arguments [0] to arguments [foo .length-1]


如果没有,是否可以获得参数的数量?

If not, is it possible to get the number of arguments?

foo.length 可以使用

这篇关于是否有可能反映Javascript函数的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆