I'm pretty new in JS and something weird happen to me. I try to set different value in an object and all the value of the table are changed It appears the problems come from the creation of the object via a the object call "materialStd"
Value obj.line[0].material.flow
of should stay at 123 instead of 3
Is someone able to explain what is happening there Thanks
https://jsfiddle.net/vx6fno9p/5/
var materialStd = {
flow: 123,
name: 'Raoul'
};
var obj = {
id: 0,
line: [{
id: 1,
material: materialStd
},
{
id: 2,
material: materialStd
},
{
id: 3,
material: materialStd
}
]
}
testerror();
function testerror() {
console.info(obj);
//On appel une fct test
console.log('' + obj.line[0].material.flow);
console.log('' + obj.line[1].material.flow);
console.log('' + obj.line[2].material.flow);
test(obj);
console.log('' + obj.line[0].material.flow);
console.log('' + obj.line[1].material.flow);
console.log('' + obj.line[2].material.flow);
}
function test(objetTraiter) {
// objetTraiter.line[0].material.flow=1;
// objetTraiter.line[1].material.flow=2;
objetTraiter.line[2].material.flow = 3;
console.log('' + objetTraiter.line[0].material.flow);
console.log('' + objetTraiter.line[1].material.flow);
console.log('' + objetTraiter.line[2].material.flow);
}