This week, I got a new idea to achieve neat code for import, Along with the original idea, I could say here is the best JS package/import framework!
Code Sample:
Declare packages:
$package('net.sf.sarissa').
bindSrc('scripts/sarissa/sarissa.js#Sarissa');
$package('a.b.c').
bindSrc('scripts/test.js#Test');
scripts/test.js
$import (net.sf.sarissa.Sarissa);
function Test(url) {
this.doc = Sarissa.getDomDocument();
doc.load(url);
...
}
another js which use a.b.c.Test
$import (a.b.c.Test);
var test = new Test('test.xml');
assert (typeof Sarissa == 'undefined'); // not like the original PIES, as my new idea, Sarissa will not need to be exported to global namespace.
本文介绍了一种新的JavaScript包管理方案,通过特定语法声明并绑定资源路径,实现了模块的按需加载,避免了将依赖项暴露到全局作用域中。
483

被折叠的 条评论
为什么被折叠?



