Online Demo HTTP://RUNJS.CN/DETAIL/BJK0ZQFL
(function () {//write JS with closure is the most common method var API = this. Api = {}; This simple regular is to be used with var ez =/^function.+\ ((. *) \) \s*{\s*\/\*+ ([\s\s]*) \*+\//; Some private methods, which do not expose the API to the user using function private () {///something}////////Api.show are visible to the user, we write the comments into the function Api.s how = function (msg) {/* Alert msg */Alert (MSG)}///Below is the simplest API Doc generation method Api.docez = Docez func tion Docez (obj) {/** docez generate JavaScript API DOC data is different from extracting annotations directly from the source, ignoring private methods directly. */var COMMENT,API = object.create (null); obj = obj | | This for (var name in obj) {if (typeof obj[name]!== ' function ') {continue} comme NT = Ez.exec (obj[name].tostring ())//no annotations, simple skip if (!comment) Continue api[name]={ PARAMS:COMMENT[1], desc:comment[2]}} return API}///below Extract API documentation and show it in JSON document.getElementById (' Apidoc '). InnerText = Json.stringify (Api.docez (), null,4)}) ()
Write annotations inside the function--easily generate JavaScript API Doc