jsSwitch语句优化
作者:互联网
// Longhand switch (data) { case 1: data1(); break; case 2: data2(); break; case 3: data(); break; // And so on... } // Shorthand var data = { 1: data1, 2: data2, 3: data }; const val = 1 data[val](); function data1() { console.log("data1"); } function data2() { console.log("data2"); } function data() { console.log("data"); }
标签:语句,case,console,log,data1,优化,jsSwitch,data,data2 来源: https://www.cnblogs.com/konglxblog/p/15758875.html