Skip to content

Instantly share code, notes, and snippets.

@oxechicao
Created September 14, 2019 19:24
Show Gist options
  • Save oxechicao/9eeeca1d02c90a95b77f42684c7d7fb4 to your computer and use it in GitHub Desktop.
Save oxechicao/9eeeca1d02c90a95b77f42684c7d7fb4 to your computer and use it in GitHub Desktop.
Modificando Independente Classes
class C {
constructor(nPesos){
this.num = nPesos;
this.pesos = [];
for(let i=0;i < nPesos;i++){
this.pesos[i] = Math.random() * 10;
}
}
}
class R {
constructor(c) {
this.c = c;
this.tes = Math.random() * 10;
}
}
var vetor = [];
var oldR = new R(new C(10))
// Se remover o Object.assign({}, obj) não funcionará
vetor.push(Object.assign({}, oldR))
function novo (vetor) {
for (var i = 0; i < 2; i++) {
vetor.push(Object.assign({}, new R(new C(i + 1))))
}
}
novo(vetor)
vetor[0].tes = 5;
console.log(vetor)
console.log(oldR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment