Код: Выделить всё
let num1;
function initNum() {
num1 = { x: 20, y: 30 };
}
function changeNum() {
num1 = { x: 0, y: 0 };
}
function newfunc() {
let var1 = {
left: num1.x,
right: num1.y,
};
console.log(var1); //x = 20, y = 30 as expected
changeNum();
console.log(var1); //x still 20, y still 30 why?
}
initNum();
newfunc();Подробнее здесь: https://stackoverflow.com/questions/797 ... the-object
Мобильная версия