Sunday 5 April 2015

Assign object to another variable in Sencha Touch

In Sencha Touch, if we need to assign the Object variable (that contains properties and methods) to another variable, usually developers will write the code as

var obj1 = origObj;

From the above code, both variable obj1 and origObj will point to the same memory location. If we change any properties in obj1, the same will get updated in origObj.

If we need to create a new object from the existing objects,  that will reference to new memory location. Here is the sencha touch code.

var obj1 = Ext.merge({}, origObj);

Now, both obj1 and origObj variable will not point to the same memory location. Here is the documentation reference for Ext.merge().

Hope, you enjoyed this post.

No comments:

Post a Comment