Javascript Reference Outer Object From Inner Object
- by Akidi
Okay, I see a few references given for Java, but not javascript ( which hopefully you know is completely different ). So here's the code specific :
function Sandbox() {
var args = Array.prototype.slice.call(arguments)
, callback = args.pop()
, modules = (args[0] && typeof args[0] === 'string' ? args : args[0])
, i;
if (!(this instanceof Sandbox)) {
return new Sandbox(modules, callback);
}
if (!modules || modules[0] === '*') {
modules = [];
for (i in Sandbox.modules) {
if (Sandbox.modules.hasOwnProperty(i)) {
modules.push(i);
}
}
}
for (i = 0; i < modules.length; i++) {
Sandbox.modules[modules[i]](this);
}
this.core = {
'exp': {
'classParser': function (name) {
return (new RegExp("(^| )" + name + "( |$)"));
},
'getParser': /^(#|\.)?([\w\-]+)$/
},
'typeOf': typeOf,
'hasOwnProperty': function (obj, prop) {
return obj.hasOwnProperty(prop);
},
'forEach': function (arr, fn, scope) {
scope = scope || config.win;
for (var i = 0, j = arr.length; i < j; i++) {
fn.call(scope, arr[i], i, arr);
}
}
};
this.config = {
'win' : win,
'doc' : doc
};
callback(this);
}
How do I access this.config.win from within this.core.forEach? Or is this not possible?