/ / ¿Cómo abarcar el objeto secundario al primario? - javascript, objeto, alcance, prototipo

¿Cómo hacer un alcance niño a objeto principal? - javascript, objeto, alcance, prototipo

Tengo el siguiente código:

define(function() {

var core = function() {};
var module;

core.prototype.module = {
setModule: function(name) {
this.module = name;
module = name;
}
};

core.prototype.sandbox = {
getModules: function() {
// will throw undefined
console.log(this._module);
// will maybe not throw an error?
console.log(modules);
}
};

});

define(["kernel"], function(Kernel) {
var sampleCore = new Core();
sampleCore.setModule("test");
sampleCore.getModules();
});

Como puede ver, no puedo acceder al otro espacio de nombres con este enfoque. ¿Hay alguna otra forma de acceder a este módulo de alguna manera?

Saludos

Respuestas

1 para la respuesta № 1

¿Qué tal establecer un parámetro para el objeto ?:

core.sandbox = {
register: function(obj, name) {
console.log( obj.module );
}
};

var a = new core.module.load(/* ..., .... */);

core.sandbox.register( a );

0 para la respuesta № 2

Utilizar core.module._modules

core.sandbox = {
register: function(name) {
var modules = core.module._modules;
}
};

0 para la respuesta № 3

Como dije en un comentario, tal vez puedas agregar un ese variable al objeto central, para que las otras funciones tengan algo en común para aferrarse?

define(function() {
var core = function() {
var that = this;
};
var module;
core.prototype.module = {
setModule: function(name) {
that.module = name;
module = name;
}
};

core.prototype.sandbox = {
getModules: function() {
console.log(that.module);
}
};

});