Page History
...
Code Block |
---|
/** * A simple demo function that outputs some text * @author Tom * @private * * @param {String} text The text that will be written to the output * @throws (String) * returns Boolean * * @example try { * saySomething('Hello world!'); * } catch(e) { * * } * * @see application.output * @since 1.0 * @version 1.0.1<br> * - Added some more JSDoc tags for the demo */ function saySomething(text) { if (text == null || text.length == 0) { throw "Invalid input!" } application.output(text); return true; } |
Where Does JSDoc Come
...
from and which Syntax Is Supported
JSDoc is not a official standard, but the defacto standard is is defined by the JSDoc Toolkit project. The other major definer of JSDoc is Google Closure Compiler's support for JavaScript annotation.
...
See Annotating JavaScript Using JSDoc and Annotating JavaScript Using JSDoc below for the supported tags and their syntax.
Working
...
with JSDoc
...
in the Script Editor
As mentioned in the intro, the Script Editor in Servoy Developer utilizes JSDoc to improve the quality of code completion and validation.
...
Expression name | Syntax example | Context | Comments |
---|---|---|---|
Named type | {String} | @param, @return, @type, @throws | The complete list of available types can be seen by triggering Code Completion inside the curly braces in the Script Editor |
Any type | {*} | @param, @return, @type, @throws |
|
OR type | {String|Number} | @param, @return, @type, @throws |
|
REST type | {...String} | @param | Can only be used for the last declared parameter of a function |
Array type | {String[]} {Array<String|Number>} | @param, @return, @type, @throws |
|
Object type | {Object<String>} | @param, @return, @type, @throws |
|
Object type with optional properties | { {name:String, [age]:Number}} | @param, @return, @type, @throws |
|
Function type | {function(String, Number, Array<Object>):Boolean} | @param, @return, @type |
|
JSFoundset type | {JSFoundset<db:/udm/contacts>}1 | @param, @return, @type |
|
JSRecord type | {JSRecord<db:/udm/contacts>}1 | @param, @return, @type |
|
JSDataSet type | {JSDataSet<{name:String, age:Number}>} | @param, @return, @type |
|
RuntimeForm type | {RuntimeForm<superFormName>} | @param, @return, @type |
|
...