Hi I'm using this module pattern variant and I'm looking for the best way to get access to a parent object. I realise there is no way to know what parents an object has so I want to include some context in the constructor. I thought this would work but it doesn't, any ideas?
$(document).ready(function(){
var main = new Main();
});
function Main() {
var one = 'hello';
init();
function init() {
var data = new Data(this);
var two = data.load();
console.log(one+' '+two);
data.output();
}
}
function Data(context) {
// public vars / methods
var pub = {
'load' : function() {
return ('world');
},
'output' : function() {
var one = context.one // <-- what should this be?
var two = this.load();
console.log (one+' '+two);
}
}
return pub;
}
The output is:
hello world
undefined world