如何调用一个函数,其名称是通过在node.js中组合一些变量来动态创建的
How can i call a function, whose name is dynamically created by combining some variables in node.js?
>我在 Node 中有一个构造函数.js
function Response() {
var numberOfArguments = arguments.length;
var getArguments = arguments;
var newConstructor = arguments.callee.name + i; // ie, (Constructor Name + numberOfArguments)
/* Here i want to call the constructor with the value in newConstructor and pass the arguments in getArguments*/
// ie, call function like Response0();
// Response1(getArguments[0]);
}
function Response0() {
//Constructor Body for Response0()
}
function Response1(sid) {
//Constructor Body for Response0()
}
现在我的问题是我如何根据进入 Response 构造函数的参数数量调用这些函数 Response0() 或 Response1()。
我没有
尝试过这个,但也许这是一种方法:
Response0() {
//Constructor Body for Response0()
}
Response1(sid) {
//Constructor Body for Response0()
//NOTE: sid will be an array of length 1
}
//here we create kind of a lookup table that binds constructors to a specific number of arguments
var dictionary = {
0 : Response0,
1 : Response1
};
Response() {
var args = Array.prototype.slice.call(arguments),
numberOfArguments = args.length;
if (dictionary.hasOwnProperty(numberOfArguments) {
//here we call the constructor and give an array of the current args to work with
new dictionary[numberOfArguments](args);
}
}
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- 如何使用 node.js 比较两个 json 数组
- 根据id将json数组组合为一个json数组
- Node.js's Buffer.writeFloatBE in Javascript
- node.js:setInterval()正在跳过调用
- 接受不在列表中的值-引导组合框
- 如何处理node.js节点mongodb中的连接和查询队列
- Node.js正在更改应用程序以使用集群模块
- 如何使用Node.js最有效地解析网页
- 在openshift node js应用程序中获取请求
- 从客户端获取修改后的对象,并将其与服务器上的原始对象组合
- 正在删除node.js中已验证的网站
- 组合两个javascript函数
- 与运行长作业(javascript,node.js)的第三方API同步的最佳实践
- Telerik rad组合框多列数据绑定
- 如何调用一个函数,其名称是通过在node.js中组合一些变量来动态创建的
- 什么's是在Node.js中公开和组合错误的最佳方式
- 如何在Node.js中组合来自不同回调的数据
- 在一个node.js进程中组合两个主循环
- 用于Node.js的Interactive Brokers TWS API客户端库-组合订单