Version1 /
ParameterAn accessor may specify parameters in the body of the
A parameter, unlike an input, is not expected to change value during the execution of a swarmlet. NOTE: Perhaps it should be required that whenever a parameter value is changed, the setup() function is re-executed. This could be useful, for example, if the possible values of one parameter depend on the value of another parameter. For example, the following accessor will send the value of the foo parameter to its output bar once: exports.setup = function() { this.parameter('foo', {'value':'y', 'type':'string'}); this.output('bar'); } exports.initialize = function() { this.send('bar', this.getParameter('foo')); } The parameter() function takes one or two arguments, a name (a required string, recommended to be camelCase with a leading lower-case character) and an object with any of the following options:
The name is required to be distinct from other inputs, outputs, and parameters. It may match the name of a parameter in a base accessor (specified by either extend() or implement()), in which case the options will override those specified in the base. Getting ParametersThe current value of a parameter may be retrieved in the accessor's JavaScript code using the getParameter() function, as in the following example: var address = this.getParameter('bridgeIPAddress'); The getParameter() function takes one argument, the parameter name (as a string). If no value option is given, then getParameter() will return null if the host has not provided a parameter value. Setting ParametersThe current value of a parameter may be set in the accessor's JavaScript code using the setParameter() function, as in the following example: this.setParameter('bridgeIPAddress', '128.32.12.0'); This might be done, for example, in an accessor that extends another to change the default value of the parameter. See Also |