关于缩小逻辑的问题。
// Assumptions:
//com.example.dummy ns is available
//com.example.dummy.type is defined immutable -> Object.defineProperty
var test, test1, test2;
function execute_case(id) {
switch(id) {
case 0:
test = com.example.dummy.type;
break;
case 1:
test1 = com.example.dummy.type;
break;
case 2:
test2 = com.example.dummy.type;
break;
default:
console.log("default");
break;
}
}
YUI压缩器压缩它,
var test,test1,test2;function execute_case(a){switch(a){case 0:
test=com.example.dummy.type;break;case 1:test1=com.example.dummy.type;break;
case 2:test2=com.example.dummy.type;break;default:console.log("default");break}};
压缩机执行以下优化是不合逻辑的?
var test, test1, test2;
var st = com.example.dummy.type;
function execute_case(id) {
switch(id) {
case 0:
test = st;
case 1:
test1 = st;
break;
case 2:
test2 = st;
break;
default:
console.log("default");
break;
}
}
可以看出,这里的压缩效果更好。
var test,test1,test2;var st=com.example.dummy.type;function execute_case(a){
switch(a){case 0:test=st;case 1:test1=st;break;case 2:test2=st;break;
default:console.log("default");break}};
答案 0 :(得分:1)