I have created a module that I use to write to a global array like so:
class SomeLibrary {
constructor( product ) {
if (typeof window.globalArray === 'undefined'){
window.globalArray = [];
}
this._someVal = 0;
}
.
.
.
addToGlobalArray( obj ) {
obj.someVal = this._someVal;
window.globalArray.push( obj );
this._someVal++
}
.
.
.
.
}
let someLib = new SomeLibrary();
someLib.addToGlobalArray({test: 'hello'})
someLib.addToGlobalArray({test: 'hello again'});
And want my 'globalArray's 'someVal' to use the current value of _someVal from the module not the reference for the result to look like:
//I want this outcome
[
{test: 'hello', someVal: 0},
{test: 'hello again', someVal: 1}
]
Not (as it currently operates)
//I don't want this outcome
[
{test: 'hello', someVal: 1}, //someVal here is 1 as it is a reference to the current value of _someVal in the module
{test: 'hello again', someVal: 1}
]
What do I need to do to pass the value and not the reference into the global Object?
(I don't have access to jQuery or Underscore)