0

I'm new to attempting to use JSDocs, and I've recently just learnt about closures, modules in javascript.

I'm trying to document my js file that has the following basic structure (there are actually many more parameters and methods). I've tried several ways to document using JSDocs without much success.

/**
 * saveRecord is a client script function for a save event
 * @param {string} type - Mode the record is in (edit, copy, create)
 * @returns {boolean}
 */
function saveRecord(type) {
    /**
     * myRepChanger()
     * This function encapsulates all variables and methods used withing myRepChanger
     * @returns {Object} object containing public api methods
     * @namespace myRepChanger
     */
    var myRepChanger = (function() {

        // private parameters
        var _salesRepID;

        // I tried several methods to document this

        // private methods
        var _getSaleTeamCount = function() {
            // some code
        }

        // public methods
        /**
         * addSalesRep()
         * addSalesRep is a function that adds a sales rep
         * @param {String} newRepID - The ID of the new sales rep to add
         * @returns {} returns nothing
         */
        var addSaleRep = function(newRepID) {
            // some code
        }
        var changeRep = function(options) {
            // some more code including options object
        }

        // API methods
        return {
            'addSalesRep' : addSalesRep,
            'changeRep' : changeRep
        }
    })();
  // more code including returning the boolean
}

If anyone can shed some light on the proper way to document this using JSDocs that would be amazing as I'm just about ready to throw in the towel on using it. Thanks!

Rob G
  • 140
  • 1
  • 11
  • What is the point of this if `saveRecord` doesn't return anything... – elclanrs Jun 14 '16 at 20:20
  • Which part? Your function does not actually return anything. – Alexander O'Mara Jun 14 '16 at 20:20
  • Its for Netsuite where we provide the function name 'saveRecord' to fire in response to a save event on a record. I've also left out where I'm using myRepChanger. I'm encapsulating myRepChanger to avoid naming conflicts and to add several modules to the code. – Rob G Jun 14 '16 at 20:22
  • Later in the code I use myRepChanger. for example, myRepChanger.init(); and myRepChanger.changeRep({'replaceAll' : false, 'newRepID' : _userID}); I just really don't know how to use JSDocs to document nested functions like this. saveRecord does return a boolean also, I just haven't added that in this sample as the outer function is easy to document, just not the inners. – Rob G Jun 14 '16 at 20:26
  • @AlexanderO'Mara - I'm trying to document a couple different parts, the module pattern creation: var myRepChanger = (function() { , and then harder for me was the internal private and public methods like addSalesRep. Thanks – Rob G Jun 14 '16 at 20:48
  • @elclanrs - thanks, I edited the original post to show the return. – Rob G Jun 14 '16 at 20:49

0 Answers0