JavaScript: Shared Secrets

function gizmo(id, secret) {
    secret = secret || {}
    secret.id = id;
    return { 
        toString: function () {
            return "gizmo " + secret.id;  
        };
    };
}

function hoozit(id) {
    var secret = {},
        that = gizmo(id, secret);
    that.test = function (testid) {
        return testid === secret.id;
    };
    return that;
}

JavaScript: Privileged

function powerConstructor() {
    var that = object(oldObject), privateVariable;
    function privateFunction(x) {
        //privateVariable
    }
    
    that.firstMethod = function (a, b) {
         //I can access private values
    };
    
    that.secondMethod = function (c) {
         //I can access private values
    };
}
  • 1
  • 2