Monday 10 April 2017

How to correctly define JSDoc for Node.js modules in extends/inherit case

I've got three Node.js modules. One called user gets inherits from base module. The handler module interacts with an instance of user:

Base module - which get's extended

/**
 * Base module
 */
'use strict';
const _ = require("underscore");

module.exports = {

    name: "base",

    /**
     * Extent object helper
     */
    extend: function(child) {
        return _.extend({}, this, child);
    },

    /**
     * Delegate event method
     */
    delegate: function () {
      //some delegate event
    }
};

User module - like a model.

/**
 * User module
 */
'use strict';
const BaseController = require("./base");

module.exports = BaseController.extend({

    name: "user",

    /**
     * Init function
     */
    init: function() {
    }
});

Handler - like a controller

/**
 * Handler module
 */
'use strict';
const user = require("./user");

module.exports = {

    name: "handler",

    /**
     * Some action
     */
    someAction: function() {
      user.delegate(); // <-- delegate() is not known as a method of "user"
    }
};

The important part in the codes is marked with an comment // <-- delegate() is not known as a method of "user" because its inherits by base module. I realy like to know how to create a full JSDoc on this modules to make my IDE supporting autocompletion on my code, expecially for user.delegate(). A answer which provides all must-have JSDoc-Blocks whould be great deal!



via lin

No comments:

Post a Comment