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

查看:23
本文介绍了是否可以反映 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]arguments[foo.length-1]

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

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

foo.length 会起作用

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

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