【发布时间】:2017-03-05 03:31:12
【问题描述】:
假设我有一个使用 require('require-all') 创建的对象
tasks = {
getProfile: [constructor function]
initAll: [constructor function]
login: [constructor function]
};
如何在不使用eval 的情况下以编程方式向 API 添加适当的方法?
API.prototype.getProfile = function(){
this.runTask(new tasks.getProfile());
};
API.prototype.initAll = function(){
this.runTask(new tasks.initAll());
};
API.prototype.login = function(){
this.runTask(new tasks.login());
}
这些任务需要能够递归运行,再次调用自己的runTask(所以我真的需要一些程序等效的东西)
【问题讨论】:
-
使用
var func = new Function(argNames,functionBody);在MDN上查找 -
这仍然有点像使用
eval但好吧,我接受。
标签: javascript node.js loops syntax nested-loops