Child pages
  • Annotating JavaScript Using JSDoc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 JSDoc Tags and Type Expressions 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}
{Boolean}
{Number}
{XML}
{XMLList}
{RuntimeForm}
{RuntimeLabel}
{JSButton}
{JSForm}

@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

{*}
Any type of value

@param, @return, @type, @throws

 

OR type

{String|Number}
Either a String or a Number

@param, @return, @type, @throws

 

REST type

{...String}
Indicates one or more String values

@param

Can only be used for the last declared parameter of a function

Array type

{String[]}
{Array<String>} 
An array containing just string values 

{Array<String|Number>}    
 An array containing string and/or number values 

{Array<Byte>}
An array containing just bytes

@param, @return, @type, @throws

 

Object type

{Object<String>}
An object where the value for each key is a String value

{Object<Array<String>>} 
An object where the value for each key contains arrays that in turn contains only string values

{ {name:String, age:Number}} 
An object with a "name" and "age" key, with resp. a string and number value

@param, @return, @type, @throws

 

Object type with optional properties

{ {name:String, [age]:Number}}
{ {name:String, age:Number=}}
An object with a "name" and optional "age" key, with resp. a string and number value

@param, @return, @type, @throws

 

Function type

{function(String, Number, Array<Object>):Boolean}
Between the bracket of the function the types of the function parameters can be sprecified. The functions returnType can be specified after the closing bracket, prefixed by a colon

@param, @return, @type

 

JSFoundset type

{JSFoundset<db:/udm/contacts>}1  
A JSFoundSet from the contacts table of the udm database server

{JSFoundset<{col1:String, col2:Number}>}
A JSFoundSet with dataproviders "col1" and "col2" with resp. string and number types

@param, @return, @type

 

JSRecord type

{JSRecord<db:/udm/contacts>}1
A JSRecord from the contacts table of the udm database server

{JSRecord<{col1:String, col2:Number}>}
A JSFoundSet with dataproviders "col1" and "col2" with resp. string and number types

@param, @return, @type

 

JSDataSet type

{JSDataSet<{name:String, age:Number}>}
An JSDataSet with a "name" and "age" column, with resp. a string and number value

@param, @return, @type

 

RuntimeForm type

{RuntimeForm<superFormName>}
A RuntimeForm that extends superFormName

@param, @return, @type

 

...