Defining a class as a type with Google Closure
If I have code like this:
var x = {};
/**
* @constructor
* ???
*/
x.MyClass = function() {
};
x.MyClass.prototype = {
hello: "Hello World",
/**
* @return {x.MyClass}
*/
y: function() {
console.log(this.hello);
retu开发者_开发问答rn this;
}
};
Closure tells me that this is x.MyClass
is not a defined type. How can I make it a defined type?
Your sample works for me, changing x.MyClass to x.MyClassX results in a error, but this sample succeeds. What release are you using?
At http://closure-compiler.appspot.com:
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// @warning_level VERBOSE
// ==/ClosureCompiler==
var x = {};
/**
* @constructor
* ???
*/
x.MyClass = function() {
};
x.MyClass.prototype = {
hello: "Hello World",
/**
* @return {x.MyClass}
*/
y: function() {
console.log(this.hello);
return this;
}
};
精彩评论