AMD's correct way to do this would be (borrowed code sample from @Eamonn O'Brien-Strain):
requirejs.config({ paths: { Q: 'lib/q' } }); function square(x) { return x * x; } function plus1(x) { return x + 1; } require(["Q"], function (q) { q.fcall(function () { return 4; }) .then(plus1) .then(square) .then(function (z) { alert("square of (value+1) = " + z); }); });
This Q method does not flow into the global area, and it is easy to find all modules depending on this library.
source share