State container

by Raynos

JavaScript

var Container = function(o) {
    var complexObject = o;

    this.get = function() {
        // return complexObject  
    };

    this.update = function(newObj) {
        // set complexObject 
        // and record any changes between call of .get & .update
    };

    this.showChanges = function() {
        // show changes recorded in update or internally recorded    
    };
};

var foo = new Container({
    "foobar": 4
});

var o = foo.get();

//o.foobar = 5;
// call to update is optional. If it can be tracked solely from get that would be great
foo.update(o);

foo.showChanges(); // alerts that foobaz changed by +1