An alternative to if/else and switch in JavaScript - Waxo
→
http://blog.wax-o.com/2015/05/an-alternative-to-if-else-and-switch-in-javascript/
Comment éviter un switch ou un if/else en javascript : avec un tableau :)
let values = {
a: 1,
b: 2,
};
let foo = values[ bar ] || 3;
est équivalent à
let foo = '';
if ( bar === 'a' )
foo = 1;
else if ( bar === 'b' )
foo = 2;
else
foo = 3;
Thu Apr 28 16:04:19 2016
–
#permalink