How do you correctly use Require.js
to load a module that returns a constructor function that has require dependencies?
My problem seems to be a scope issue, I have seen some modules that are available within the returned constructor like "durandal/app" and I dont see how they are scoped any different than the modules I have defined.
This example is modified from Durandal Creating a Module docs
define([**someothermodule**, "durandal/app"], function(**someothermodule**, app){
var backend = function(username, password){
this.username = username;
this.password = password;
someothermodule.whatever(); <--someothermodule is not defined
app.whatever(); <-- this is in scope
};
backend.prototype.getCustomers = function(){
//do some ajax and return a promise
};
return backend;
});
define([backend], function(backend){
return {
customers:ko.observableArray([]),
activate:function(){
var that = this;
var service = new backend('username', 'password');
return service.getCustomers().then(function(results){
that.customers(results);
});
}
};
});
Someothermodule:
define([], function(){
var whatever = function(){
alert("whatever");
};
return {
whatever: whatever
};
});