-
globals are not evil. globals are what we have, in JavaScript, and they are not going away. Using good judgement, just avoid them when necessary, but use them where they make sense.
-
where.js is a testing library, not a production application library. The danger of colliding with another global named "where" is vanishingly small, especially in tests.
-
Jasmine, Mocha, QUnit ("... and the rest") all work this way in the browser. In order run jasmine on node.js, jasmine-node does the same thing, making jasmine a global. qunitjs works the same way on node.js. The library by J.P. Castro that in part inspired me to work out where.js also declares a global,
using
. -
I can
require()
my code under test into a test file on Node.js, but must I really require the test file be that kind of module rather than a script? -
Does it makes sense for where.js tests with mocha, jasmine, QUnit, etc., on both node.js and browsers, to depend on "build" steps for tests written for platform-agnostic code, especially interpreted code that should just run? Avoiding that step reduces dependencies in your tests and test subjects.
-
-
Save dfkaye/9129150 to your computer and use it in GitHub Desktop.
Explicitly defining a global for the user seem prescriptive when there is no need to be.
Also, I do believe globals are going away marginally soon. With ES6 module scope + commonjs module scope.
Keeping it simple, just require('where')
and where
is available.
IMO, as I'm sure you've guessed, is that the module patterns are code bloat. If you have to enforce any, they should be as small as possible and work on multiple environments without requiring builds.
The my.namespace.pattern
works on both node.js and browsers, is well-understood but until recently has been accidentally clobberable, like globals.
The synchronous nature of require()
in node.js appears to solve that problem for re-use but actually encourages shell script style code (imperative), not modular code (declarative).
Doesn't it make sense to just use UMD, and if people want to export it globally they can? (Like how chai assertions work)