简体   繁体   中英

How to define constructor with closure and factory method with Google Closure

I'm trying to build a constructor function with the Google Closure library.

To do so, I have a closure that return a factory method that export the constructor:

(function(factory) {
    namespace.ui.Modal = factory();
})(function() {
    var Modal = function() {};
    goog.inherits(Modal, namespace.ui.Base);

    return Modal;
});

This fails the build with the closure compiler. How could I annotate this code so it works as is inside closure compiler?

The standard pattern for a constructor would be:

/**
 * @constructor
 */
namespace.ui.Modal = function() {
  /** @private {string} */
  this.field = "oh no, not hello again";
}
goog.inherits(namespace.ui.Modal, namespace.ui.Base);

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM