I am trying to flush some data by replacing it entirely with an object that has a set of keys with empty values.
e.g.
const sportPrototype = {
name: '',
players: '',
displacement: '',
points: '',
leagues: []
}
var profileScratchpadOne = {
sportScratchpad: {
name: 'Soccer',
players: '16',
displacement: 'Foot',
points: 'unlimited',
leagues: ["Fifa"]
}
}
profileScratchpadOne.sportScratchpad = sportPrototype
profileScratchpadTwo.sportScratchpad = sportPrototype
Whenever a value in either sportScratchpad
s gets changed, it does in both profileScratchpadOne
and profileScratchpadTwo
.
I figure a reference is being passed.
I have investigated spread operator, prototypes, constructors, and have yet to find a bulletproof, concise approach.
What is the most succinct way of getting around this, and passing a fresh object every time?