开发者

Defining a class as a type with Google Closure

开发者 https://www.devze.com 2023-03-19 17:15 出处:网络
If I have code like this: var x = {}; /** * @constructor * ??? */ x.MyClass = function() { }; x.MyClass.prototype = {

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;
   }
};
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号