I’m looking for a way to minimize the creation of an array where all indexes would have the same value. It might not be possible, but I would find it very handy.
Consider:
var layer = [];
layer['game'] = new Kinetic.Layer();
layer['navigation'] = new Kinetic.Layer();
layer['notification'] = new Kinetic.Layer();
(where Kinetic.Layer is an object, however I suspect that it doesn’t matter)
Looking for something like:
var layer['game','navigation','notification'] = new Kinetic.Layer();
Is this even possible? It, of course, isn’t truly needed – but i would find it very handy, repeating code is kinda a bad practice.
And no, I can’t have one single index or variable, as theese objects will change later in my code – and they have to be declared before usage.
In this case a shorthand would NOT be the same, as all three would point to the same
Kinetic.Layerinstead of having three different Layers.So, in your case, do NOT attempt a shorthand.
However in general, you can assign the same value to several variables like this:
Side-note: You’re using an array object
[]and then assigning string keys – this isn’t strictly correct, and you should be using a generic object{}instead.