Instructions

When the page first loads, a Session is created and started which checks for the cookie 'mint-slice', containing the serialized MyObject object. If the cookie doesn't exist, a new MyObject is created and written to the session.

Session

Serialized XML

Object Code to be serialized

     function OtherObject(name) {
        this.name = name;
        this.getName = function() {alert(this.name)};
        this
      }      
      
      function MyObject() {  
        this.x = 1;
        this.foo = new Array("boo","foo","fum");
        this.obj = new OtherObject('Matt\'s other ojbect');
        this.objArray = new Array(new OtherObject('foo object 1'), new OtherObject('foo object 2'), new OtherObject('foo object 3'));
        this.objArray = new Array(new OtherObject('footy'));
        var cool = "cool";
        this.callInternalFunction = function() {
          internalFunction();
        }
        internalFunction = function() {
          alert('Calling an internal function and display encapsulated var cool: '+cool);
        }
      }
      
      MyObject.prototype.addItem = function(item) {
        this.foo[this.foo.length] = item;
      }
      
      MyObject.prototype.display = function() {
        for(var i = 0; i < this.foo.length; i++) {
          alert(this.foo[i]);
        }
      }

      MyObject.prototype.displayObjs = function() {
        for(var i = 0; i < this.objArray.length; i++) {
          this.objArray[i].getName();
        }
      }
      
      MyObject.prototype.getX = function() {
        alert(this.x);
      }
      
      MyObject.prototype.displayObj = function() {
        this.obj.getName();
      }
      
      var myObject = new MyObject();