jeudi 26 février 2015

how to create a separate copy of properties in ember js

After my latest update of ember-cli to 0.1.12 array.slice and jquery.extend is not creating a separate copy of arrays and objects.


Eg:



//Arrays
{
arrayProp: [a,b,c],

someFunction: function () {
var localArrayProp = this.get('arrayProp').slice(0);
localArrayProp.push('d');
/*
Now both arrayProp and localArrayProp will be a,b,c,d

This was not the case before updating, before updating arrayProp was a,b,c and localArrayProp was a,b,c,d
*/
}
}

//objects
{
objectProp: {'key1':'val1', 'key2':'val2'},

someFunction: function () {
var localObjectProp = $.extend({},this.get('objectProp'));
localObjectProp.key3 = 'val3';
/*
Now both objectProp and localObjectProp will be {'key1':'val1', 'key2':'val2', 'key3':'val3'}

This was not the case before updating, before updating objectProp was {'key1':'val1', 'key2':'val2'} and localObjectProp was {'key1':'val1', 'key2':'val2', 'key3':'val3'}
*/


}
}


Also now how to obtain the above.A bit urgent please!





Aucun commentaire:

Enregistrer un commentaire