I’m not sure why this isn’t working. I wrapped my function in an anonymous function with the belief that it wouldn’t get evaluated until it was called elsewhere. But I’m getting an error about “dropchart” not being defined, so it’s getting evaluated within this module.
define(function() {
var stage = {
before: {
createCanvas: function() {
return function() {
before(function(done) {
this.canvas = new dropchart.Canvas({
canvas: argsFor.canvas(),
data: argsFor.data()
});
done();
});
};
}
}
};
return stage;
});
This is how it is called from the other module:
define(['jquery', 'dropchart', 'argsFor', 'stage'],
function($, dropchart, argsFor, stage) {
var should = chai.should();
var xAxisSpec = {
run: function() {
describe('xAxis', function() {
stage.before.createCanvas();
...
The
stagemodule has theargsForanddropchartdependencies, not the calling module.The calling module cannot somehow make those available for
stagemodule, unless you pass them as arguments instage.before.createCanvasor you put them to global scope which defeats the whole point of require.js