javascript - ClosureCompiler removing dead code with advanced optimizations -


the following code:

(function() {  var hello = function(name) {   alert('hello, ' + name);  }  hello('new user'); })(); 

with advanced_optimizations compiled to:

alert("hello, new user"); 

but code:

(function() {  var hello = function(name) {   alert('hello, ' + name);  }  hello.a = 5;  hello('new user'); })(); 

is compiled to:

function a(b){alert("hello, "+b)}a.a=5;a("new user"); 

why cannot ignore hello.a = 5?

(it cannot used outside context, there no eval, no [] , no new function().)

for work, compiler need determine no 1 had replaced "alert" function looked @ the calling function:

alert = function() {   console.log(arguments.callee.caller.a); } 

but "alert" external function there no way determine does. generally, javascript mutable cases properties can safely removed functions rare isn't worth effort find them.

generally, closure compiler can remove properties cheating. there discussion of here:

https://github.com/google/closure-compiler/wiki/understanding-property-removal


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -