[英]Closure Compiler Ignores Object Mutation
I put the following code into closure compiler on advanced mode: 我将以下代码放入高级模式的闭包编译器中:
var obj = (function() {
/** @constructor */
function H(a) {
this.a = a
}
var h = new H(1);
h.b=1
return h
})();
The result I get back is: 我得到的结果是:
(function() {
var a = new function() {
}(1);
a.a = 1;
return a;
})();
Why is it ignoring the change I make to the object hb=1
? 为什么忽略我对对象hb=1
所做的更改?
The advanced compilation options enable aggressive property removal , which includes some assumptions: 高级编译选项可实现主动删除属性 ,其中包括一些假设:
It makes a strong assumption that properties defined on a "prototype" or "this" will not be iterated over and thus is a candidate for removal. 它有一个很强的假设,即不会重复定义在“原型”或“此”上的属性,因此是删除的候选对象。
/** @constructor */ function cls() { this.x = 1; // removal candidate due to "this" assumption; }
So what you're seeing is actually this.a = a
being removed, and then the property b
is being renamed to a
. 因此,您实际上看到的是this.a = a
被删除,然后将属性b
重命名为a
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.