If I have an object for example
Recipes.name = "test"
and I copy Recipes to ‘d’
d = Recipes
then change d.name
d.name = "different name"
I find now Recipes.name = "different name"
Is this a planned thing with objects or a bug?
If I have an object for example
Recipes.name = "test"
and I copy Recipes to ‘d’
d = Recipes
then change d.name
d.name = "different name"
I find now Recipes.name = "different name"
Is this a planned thing with objects or a bug?
Seems this is the way to copy Objects without retaining the reference to the original object…
d = JSON.parse(JSON.stringify(Recipes))
That’s a valid way of doing this.
JavaScript copies by value on simple variables (strings, numbers) and copies by reference for objects.
There are many articles with discuss this. Here’s one.