2016-03-29 12 views
1

Ich benutze NodeJS und versuchen, die JSDoc auf die Eigenschaft holen abholen, was ich tue. Ich habe einige Code, der wie folgt aussieht:Wie dokumentiere ich module.exports definiert mit object.defineProperty

Object.defineProperty(module, 'exports', { 
    enumerable: true, 
    configurable: true, 
    get: function() { 
     const factory = {}; 

     /** 
     * Output message to the console 
     * @param {string} str 
     */ 
     factory.foo = function(str) { 
      console.log(str); 
     }; 

     return factory; 
    } 
}); 

foo üblicher Weise exportieren exports.foo = function(str) { ... } ist keine Option in diesem Fall.

Ein anderes Modul kann beinhalten, dass dieses Modul Zugriff auf foo hat (so als ob es direkt exportiert würde). Zum Beispiel:

var x = require('./x'); 
x.foo('Hello'); 

So wie kann ich dokumentieren dies so, dass jsDoc aufgreift, dass dieses Modul eine Funktion foo hat?

Antwort

0

fand ich eine Art und Weise, die zu funktionieren scheint:

Object.defineProperty(module, 'exports', { 
    enumerable: true, 
    configurable: true, 
    get: Factory 
}); 

/** 
* Get a factory object. 
* @returns {Factory} 
* @constructor 
*/ 
function Factory() { 
    var factory = Object.create(Factory.prototype); 

    /** 
    * Output a message to the console. 
    * @name Factory#foo 
    * @param {string} str 
    */ 
    factory.foo = function(str) { 
     console.log(str); 
    }; 

    return factory; 
}