[英]is it possible to get parameters by function name in javascript
For example, I have a function defined as below: 例如,我有一个定义如下的函数:
var fn1 = function(obj, p1, p2) {}
Is it possible to get this function's parameters by the function name fn1
outside fn1? 是否可以通过fn1
之外的函数名称fn1
获取此函数的参数?
I want to make a new fn2(p1, p2)
dynamically and in this function passing the obj to call fn1
? 我想动态制作一个新的fn2(p1, p2)
并在此函数中将obj传递给fn1
?
Anyone help on this? 有人帮忙吗? Many thanks. 非常感谢。
You don't need to pass the scope to the function
like this: 您不需要像这样将范围传递给function
:
var fn1 = function(scope, p1, p2) {}
I belive what you want is something like the call
method. 我相信您想要的是类似call
方法的东西。 The call
method is used to call a method on behalf of another object. call
方法用于代表另一个对象调用方法。 It allows you to change the this object of a function from the original context to the new object specified by first arg. 它允许您将函数的this对象从原始上下文更改为first arg指定的新对象。 call
Method Ref. call
方法参考。 - JS -JS
Here some example: 这里有一些例子:
var fn1 = function(p1,p2){};
var fnThatCall = function(p1,p2){
var scpe = this;
fn1.call(scope,p1,p2);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.