I feel like having a factory run once (and only once) is necessary. It allows for proper encapsulation. In the below example, the author of MyModule will run into problems due to their factory being ran multiple times, something the MyModule author would have zero control over.
// MyModule.js
define('MyModule', function() {
var privateVariable = 1;
var myClass = function() {
privateVariable++;
};
myClass.prototype.varIs = function() {
return privateVariable;
}
return myClass;
});
// calling code that results in two define calls,
// each requires MyModule. (The MyModuleRemapped
// is normalized to MyModule)
define(['MyModule'], function(MyModule) {
var m = new MyModule();
console.log(m.varIs()); // 2
});
define(['MyModuleRemapped'], function(MyModule) {
var m = new MyModule();
console.log(m.varIs()); // 2 (expected: 3)
});
I believe this would break module authors' expectations.
--Jakob