0
我想用JSON文件動態加載和調用Javascript函數。這個想法是構建一個插件框架,讓其他人通過編寫一個函數和更新JSON文件來添加功能。動態加載Javascript函數
例如,下面的JSON:
{
"plugins" : {
"random" : {
"name" : "Random number generator",
"hook" : "random"
}
}
}
...及以下插件:random.js
module.exports.run = function() {
return Math.round(Math.random() * 100);
}
我希望能夠解析JSON文件和調用任何插件的運行功能。如何隨機加載和調用運行功能?