2
I want to pass an object per function parameter, but I don’t want that object to be changed. For this I want to pass a clone parameter.
Because in javascript, by the tests I did, the object is always passed by reference.
Example:
a = {}
b = a;
b.nome = 'Wallace';
console.log(a, b); //Object {nome: "Wallace"} Object {nome: "Wallace"}
See that the two objects have been changed.
How to do this assignment of b
for a
in javascript, without keeping the references?
Please use
document.write
in place ofconsole.log
:D– Wallace Maxters
@Wallacemaxters For visualization it looks bad, it is [Object][Object]..
– Gabriel Rodrigues
Just give
JSON.stringify
my friend :D– Wallace Maxters
Gabriel, you know why data stays inside
__proto__
when you wear it like that?– Wallace Maxters
@Wallacemaxters I’m not 100% sure, but I think it’s Inheritance. if you create an item in the object to you will see that b will inherit it, o a não tera proto but the b will have
– Gabriel Rodrigues
This method is not the best alternative.
– Lucas Fontes Gaspareto
@devgaspa Could elaborate a response by making the comparison ?
– Gabriel Rodrigues