You are very close, but you're missing something important in your definition of someMethod
.
EDIT: is is easier to tell what works and what doesn't if you change the name of the module property in ModuleB:
var ModuleA = function() {}
ModuleA.prototype = (function () {
return {
someMethod: function () {
return 'foo';
}
};
}());
var ModuleB = function(moduleA) {
this.innerModule = moduleA;
}
ModuleB.prototype = (function () {
return {
doStuff: function () {
return this.innerModule.someMethod();
}
};
}());
var moduleA = new ModuleA();
var moduleB = new ModuleB(moduleA);
console.log(moduleB.doStuff()); // prints "foo"