我希望在ADVANCED_OPTIMIZATIONS模式下重命名对象属性。优化前如何使用GCC重命名由Object.defineProperty创建的属性
代码:
/**
* @constructor
*/
function Container() {
var items = [];
Object.defineProperty(this, 'items', {
set: function(value) {
items = value;
},
get: function() {
return items;
}
});
}
var container = new Container();
container.items = [1,2,3];
console.log(container.items);
优化后:
var b = new function() {
var a = [];
Object.defineProperty(this, "items", {set:function(c) {
a = c
}, get:function() {
return a
}})
};
b.e = [1, 2, 3];
console.log(b.e);
关闭编译器不改名属性名称 - “项目”。
为什么要重命名它? – Oriol
我不认为任何编译器会自行重命名任何对象属性。自动执行是危险的。 – Thomas
我很震惊:https://developers.google.com/closure/compiler/docs/api-tutorial3#propnames我的结论:千万不要使用gcc的ADVANCED_OPTIMIZATIONS。我会使用一些外国minifyer像uglifyjs – Thomas