【发布时间】:2015-11-01 15:28:45
【问题描述】:
我需要通过只知道 string 名称来调用 module.export 对象中的函数
module.exports = {
a : function() { console.log('a'); },
b : function() { console.log('b'); },
c : function() {
var fn; // string contain the name of the function to call ('a' or 'b' for example)
// How do I call `fn` programatically from here?
// something like `self[fn]()`
}
};
【问题讨论】:
标签: javascript node.js