Referencing parent object

by MegaScience

JavaScript

// Source: http://stackoverflow.com/questions/2980763/javascript-objects-get-parent

var main = {
    name : "main object",
    child : {
        name : "child object"
    },
    init : function() {
        this.child.parent = this;
        delete this.init;
        return this;
    }
}.init();

document.body.innerHTML = main.child.parent.name;