I try to aggregate a Prototype object to a JavaScript normal object:
var ModuleA = function( data ) {
this.data = data;
};
ModuleA.prototype.funcA = function() {
alert( JSON.stringify( this ) );
}
var myMainObject = {
list: []
};
$.extend( myMainObj <--------- ???ect, new ModuleA( 'Haha' ) );
myMainObject.funcA();
Now the myMainObject will have data property and funcA function, since I merge to the myMainObject.
When I execute myMainObject.funcA, the this arguments actually is myMainObject!
To my understanding, when new a Prototype object, the function will bind to the object created with the new and pass to the constructor.
But with the jQuery extend, the this arguments is not the new object, but point to the myMainObject, which confuse me.
Is there any idea?