最佳答案
I want to check in a script if a certain other module is already loaded.
if (ModuleName) {
// extend this module
}
But if ModuleName
doesn't exist, that throw
s.
If I knew what the Global Object
was I could use that.
if (window.ModuleName) {
// extend this module
}
But since I want my module to work with both browsers and node
, rhino
, etc., I can't assume window
.
As I understand it, this doesn't work in ES 5 with "use strict"
;
var MyGLOBAL = (function () {return this;}()); // MyGlobal becomes null
This will also fail with a thrown exception
var MyGLOBAL = window || GLOBAL
So it seems like I'm left with
try {
// Extend ModuleName
}
catch(ignore) {
}
None of these cases will pass JSLint.
Am I missing anything?