3
我想知道是否有可能運行一個名爲nodejs中的字符串的函數。所有這些代碼都在服務器端運行,根本沒有瀏覽器出現。Nodejs從字符串執行導出的函數
假設我導出文件test.js
用下面的代碼
module.exports.test = function(x)
{
console.log(x*5);
}
我能做到這一點不知何故?
main.js
imp = require('test.js');
toExecute = "test";
// somehow call imp.test using toExecute`
哈!你先生是紳士和學者。謝謝! – Kartik 2012-04-17 02:41:27
np :)。請記住,JavaScript中的對象可以用裸字樣式或'[]'樣式索引。所以'module.exports.test'和'module.exports ['test']'是一樣的。 – rfunduk 2012-04-17 02:44:32
gotcha!再一次感謝你 – Kartik 2012-04-17 02:48:19