1

次のようなコードがある場合:

var x = {};

/**
 * @constructor 
 * ???
 */
x.MyClass = function() {

};

x.MyClass.prototype = {

   hello: "Hello World",

   /**
    * @return {x.MyClass}
    */
   y: function() {
      console.log(this.hello);
      return this;
   }

};

x.MyClassクロージャーは、これが定義された型ではないことを教えてくれます。定義済みの型にするにはどうすればよいですか?

4

1 に答える 1

2

あなたのサンプルは私のために働き、x.MyClassをx.MyClassXに変更するとエラーが発生しますが、このサンプルは成功します。どのリリースを使用していますか?

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;
   }
};
于 2011-07-11T21:48:26.917 に答える