我想检查脚本是否已加载其他模块。
if (ModuleName) {
// extend this module
}
但是,如果ModuleName不存在,那就是throw。
如果我知道那Global Object是什么,我可以使用它。
if (window.ModuleName) {
// extend this module
}
但是,因为我希望我的模块与浏览器和工作node,rhino等等,我不能假设window。
据我了解,这在ES 5中使用"use strict"; 无效;
var MyGLOBAL = (function () {return this;}()); // MyGlobal becomes null
这也会因抛出异常而失败
var MyGLOBAL = window || GLOBAL
所以好像我已经离开了
try {
// Extend ModuleName
}
catch(ignore) {
}
这些情况都不会通过JSLint。
我有什么想念的吗?
相关分类