Created
September 14, 2019 19:24
-
-
Save oxechicao/9eeeca1d02c90a95b77f42684c7d7fb4 to your computer and use it in GitHub Desktop.
Modificando Independente Classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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