So I am using
asArray() to create rgba color from color provided as a string. I noticed a very strange behaviour when I create two colors from same orginal string. It seems like they both reference same object.
Take a look at this:
const color = 'red'; const fillColor = asArray(color); const strokeColor = asArray(color); fillColor = 0.05; strokeColor = 0.2; console.log(fillColor); console.log(strokeColor);
[255, 0, 0, 0.05] [255, 0, 0, 0.2]
[255, 0, 0, 0.2] [255, 0, 0, 0.2]
So it seems these colors are somehow bound and changing one changes another. What I tried is to deep copy a string like this:
const fillColor = asArray(color.repeat(1)); const strokeColor = asArray(color.repeat(1));
But it still acts the same.
How do I create different colors?