我正在使用 ADVANCED_OPTIMIZATIONS 编译级别的 Google Closure Compiler 并开始注释我的构造函数,因为我收到了各种警告:
警告 - 危险地使用全局 this 对象
对于我的“构造函数”类型函数,我将像这样注释它们:
/**
* Foo is my constructor
* @constructor
*/
Foo = function() {
this.member = {};
}
/**
* does something
* @this {Foo}
*/
Foo.prototype.doSomething = function() {
...
}
这似乎工作正常,但是如果我有一个不是用 var myFoo = new Foo(); 构造的“单例”对象怎么办?我在文档中找不到如何注释这种类型的对象,因为它的类型只是对象,对吗?
Bar = {
member: null,
init: function() {
this.member = {};
}
};