Please, explain to me the best way to describe this module:
/**
* Common util methods
* @module Utils
*/
var Utils = (/** @lends module:Utils */
function () {
/**
* Some default value
* @constant
* @public
* @static
* @type {string}
*/
var staticConstantField = "Some value";
//export to public access
var exports = {
staticConstantField: staticConstantField,
getUrlArgs: getUrlArgs,
isJSON: isJSON
};
return exports;
/**
* Return url arguments as associate array
* @public
* @static
* @returns {Array} - url args
*/
function getUrlArgs() {
return [];
}
/**
* Validate json
* @public
* @static
* @param {string} json - json as string to validate
* @returns {boolean} - is json valid
*/
function isJSON(json) {
return true;
}
/**
* Some private method
* @private
* @static
* @param {string} json - json to parse
* @returns {object} - parsed object
*/
function parseJson(json) {
return {};
}
})();
In this example my @public and @static annotation are ignored, all @public methods marks as "inner", @private methods marks as "private, inner", return statement is ignored. In generated docs I don't see what methods I can use as api ('exports' object in my code) and if I return
var exports = {
anotherFieldName: staticConstantField,
anotherGgetUrlArgsName: getUrlArgs,
anotherIsJSONName: isJSON
};
this API would not show up in docs.
Generated documentation:
A quick way to solve the problem at hand would be to add a @method methodName
to each function. With this declaration the @static
property is recognized and referenced in the generated jsdoc.
/**
* Common util methods
* @module utils
*/
var utils = (/** @lends module:utils */ function () {
/**
* this variable is neither @static nor @public it's a @constant in a private scope, you can add a @private if you like
* @constant
* @private
*/
var myConstant = 'foo';
/**
* @method myMethod
* @static
*/
function myMethod(){}
return {
myMethod: myMethod
};
})();
Never the less, I doubt that this construct should be considered a module rather than a namespaced object literal. Thus I would recommend to declare it like this:
/**
* Common util methods
* @namespace
*/
var utils = (/** @lends utils */ function () {
/**
* @memberOf utils
*/
function myMethod(){}
return {
myMethod: myMethod
};
})();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With