let [moveUp, moveDown,
moveLeft, moveRight,
mouseDown, touchDown] = Array(6).fill(false);
console.log(JSON.stringify({
moveUp, moveDown,
moveLeft, moveRight,
mouseDown, touchDown
}, null, ' '));
// NOTE: If you want to do this with objects, you would be safer doing this
let [obj1, obj2, obj3] = Array(3).fill(null).map(() => ({}));
console.log(JSON.stringify({
obj1, obj2, obj3
}, null, ' '));
// So that each array element is a unique object
// Or another cool trick would be to use an infinite generator
let [a, b, c, d] = (function*() { while (true) yield {x: 0, y: 0} })();
console.log(JSON.stringify({
a, b, c, d
}, null, ' '));
// Or generic fixed generator function
function* nTimes(n, f) {
for(let i = 0; i < n; i++) {
yield f();
}
}
let [p1, p2, p3] = [...nTimes(3, () => ({ x: 0, y: 0 }))];
console.log(JSON.stringify({
p1, p2, p3
}, null, ' '));