How to copy or TypeCast a javascript object to a variable with the base class

http://stackoverflow.com/questions/15114901/how-to-copy-or-typecast-a-javascript-object-to-a-variable-with-the-base-class

by cswing

JavaScript

require(["dojo/_base/declare", "dojo/Stateful", "dijit/form/Button"], function(declare, Stateful, Button) {
   
    var MyStateful = declare("MyStateful", [Stateful], {
        postscript: function(/*Object?*/ params){
            this.inherited(arguments);
            
            var _s = this;
            this._original = params;
            
            // create watches 
            for(var x in this._original){
				if(this._original.hasOwnProperty(x) && x !="_watchCallbacks"){
                    this.watch(x, function(name, oldValue, value) {
                        _s._original[name] = value;
                    });
				}
			}
        }
    });
    
    var btn = new Button({ 
        testValue: 'test 123'
    });
    
    var stateful = new MyStateful(btn);
    
    console.debug(btn.declaredClass);
    console.debug(stateful.declaredClass);
    console.debug(stateful._original.declaredClass);
    
    stateful.set('testValue', 'test 123 - UPDATED');
    
    console.debug(btn.testValue);
    console.debug(stateful._original.testValue);
});