Javascript Reference Outer Object From Inner Object

Posted by Akidi on Stack Overflow See other posts from Stack Overflow or by Akidi
Published on 2010-05-31T00:48:39Z Indexed on 2010/05/31 0:52 UTC
Read the original article Hit count: 315

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about object