Skip to content

Instantly share code, notes, and snippets.

@flozz
Created April 5, 2018 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flozz/0cb94dbe6e79d43ba31c5727684d24fe to your computer and use it in GitHub Desktop.
Save flozz/0cb94dbe6e79d43ba31c5727684d24fe to your computer and use it in GitHub Desktop.
JSDoc examples for shpinx-js
/**
*/
class Foobar {
/**
* If we let jsdoc extracting the default values (es6 syntax), the
* result is ok for simple types (number, string, boolean and null)
*
* @param {*} a
* @param {number} [b]
* @param {boolean} [c]
* @param {string} [d]
*/
simple_type_implicite(a, b=42, c=false, d="false") {
}
/**
* If we document explicitely values, it does not works as expected:
* If something looks like a boolean or a number, it is "casted", so we
* cannot have a ``"42"`` or a ``"false"`` string
*
* @param {*} a
* @param {number} [b=42]
* @param {boolean} [c=false]
* @param {string} [d=false]
*/
simple_type_explicite(a, b=42, c=false, d="false") {
}
/**
* An other exemple with explicite documentation
*
* @param [a=42]
* @param [b="42"]
* @param [c=false]
* @param [d="false"]
*/
simple_type_explicite2(a, b, c, d) {
}
/**
* More complex types are not documented automatically...
*
* @param [obj]
* @param [arr]
* @param [fn]
*/
array_object_function_implicite(obj={}, arr=[], fn=function(){}) {
}
/**
* ... And are "casted" as string when explicitely documented (except for
* objects that does not displayed at all, jsdoc seems to dislike ``{}``
* in @param)
*
* @param [obj={}] Param JSDoc JSON: ``{"name": "obj="}``?
* @param [arr=[]]
* @param [fn=function(){}]
*/
array_object_function_explicite(obj={}, arr=[], fn=function(){}) {
}
/**
* Variable or constants as default value are not automatically
* documented...
*
* @param [a]
*/
constants_implicite(a=SOME_CONST) {
}
/**
* ... and are seen as string if documented explicitely
*
* @param [a=SOME_CONST]
*/
constants_explicite(a=SOME_CONST) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment