google-closure-compiler in advanced mode, warns for the following code. This is caused by namespace flattening.
var com.my.test.namespace = {};
com.my.test.namespace.a = new Class ({
name : "test",
initialize : function() { //constructor
alert(this.name);
}
});
com.my.test.namespace.a();
When running the google-closure-compiler in ADVANCED mode with debug enabled, com.my.test.namespace.a is replaced to com$my$test$namespace$a
So, the minified code is roughly the following,
var com.my.test.namespace = {};
com$my$test$namespace$a = new Class ({
name : "test",
initialize : function() { //constructor
alert(this.name);
}
});
com$my$test$namespace$a();
When, com$my$test$namespace$a() is invoked, "this" isn't com.my.test.namespace anymore, it is the window, and hence the compiler warning.
some documentation suggests to replace "this" with com.my.test.namespace.a to get around this issue. But, is that the right thing to do? what does com.my.test.namespace.a.name point to? It surely does not seem like the current instances "name" property.
What is the right way to do it? com.my.test.namespace.a.prototype.name ?
PS:
I am using mootools library for the Class method.