Last active
January 22, 2017 12:35
-
-
Save CreeJee/30ae798f2cd6dd3b318fc66e270822f2 to your computer and use it in GitHub Desktop.
when I'm not using eval than anything have solution?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fn = {}; | |
fn.listPlugins = function(cb){ | |
if (!Array.isArray(this.plugins)) { | |
$.getJSON('/plugins/list.json',(json, textStatus) => { | |
if (textStatus == "success") { | |
this.plugins = json; | |
if (typeof cb == "function") { | |
cb(json); | |
} | |
else{ | |
return json; | |
} | |
} | |
}); | |
} | |
else{ | |
if (typeof cb == "function") { | |
cb(this.plugins); | |
} | |
else{ | |
return this.plugins; | |
} | |
} | |
} | |
fn.getPlugins = function(name,filePath){ | |
if(Array.isArray(name) && filePath === undefined){ | |
this.listPlugins((plugins)=>{ | |
for(var k of name){ | |
this.getPlugins(k,plugins[k].path); | |
console.log(k,plugins[k].path) | |
} | |
}) | |
} | |
else{ | |
$.getScript(filePath, (data, textStatus) => { | |
if(textStatus == "success") | |
{ | |
this[name] = eval(data); | |
} | |
}); | |
} | |
} | |
//list.json | |
{ | |
"Draw":{ | |
"path" : "/plugins/Draw.js", | |
"description" : "test" | |
}, | |
"Math":{ | |
"path" : "/plugins/Math.js", | |
"description" : "test" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment