Tag: 情况

JS / node.js:大型开关块与function集合

我在Github上看到了这样的代码: switch (type) { case 'case1': return this.case1(); case 'case2': return this.case2(); case 'case3': return this.case3(); … default: return this.default(); } 它包含25个案例+默认情况。 我会用不同的方式把所有的function打包到一个对象中: var list = {}; list.case1 = function() { return /* code */; }; list.case2 = function() { return /* code */; }; list.case3 = function() { return /* code */; }; // […]