I've added a button to call this function
onPress(){
if(!this.data) this.data = this.test;
else for(var i in this.test) this.data.push(this.test[i]);
console.log(this.test.length);
}
On the first call this.test
is assigned to this.data
. I suppose it is passed by value not by reference. So when the iteration change the value of this.data
, it will not affect this.test
.
But I am wrong. this.test
's value is changed. I know the workaround is I should avoid to assign it directly. Define this.data = []
in constructor first. And iteration is the only way. But is it supposed to work that way or am I missing something?