I was writing a javascript object and to prevent duplication of aliases of the same object
For example, repeating the key for the same values here:
var colours = {
red: {
rgb: "255,0,0",
hex: "#FF0000"
},
brickred: {
rgb: "255,0,0",
hex: "#FF0000"
}
};
I tried making a reference to the same object, instead to avoid duplication:
var colours = {
red: {
rgb: "255,0,0",
hex: "#FF0000"
},
brickred: this.red
};
However, this does'nt work. I realised (I think) this is because it refers to the window object and not colours. So then I tried:
var colours = {
red: {
rgb: "255,0,0",
hex: "#FF0000"
},
brickred: colours.red
};
But this still doesn't work and I don't understand why. How can I solve this?
N.B. The example isn't very good, but basically I have an object literal and want to avoid duplication where I have different keys with same value. I'd also like to know why it doesn't work for curiosity