javascript - Concise way of defining ES6 symbols? -
if want define multiple symbols in row, syntax little verbose:
const = symbol('a'), b = symbol('b'), c = symbol('c');
i came more concise way it:
const [a, b, c] = ['a','b','c'].map(key => symbol(key))
is concise way possible, or there dedicated syntax declaring multiple symbols i'm unaware of?
p.s. 'a' 'b' , 'c' arbitrary examples of course. realize 1 clever particular example ;)
it can concise as
const [a, b, c] = ['a','b','c'].map(symbol);
there's no way skip abc tautology here because variable names should explicitly written, symbol description.
symbol descriptions helpful debugging. if can omitted (not recommended), becomes
const [a, b, c] = [,,].map(symbol);
for fixed amount of variables. and
const [a, b, c, d /*, ... */] = function* () { for(;;) yield symbol() }();
for unlimited amount of variables.
Comments
Post a Comment