JSDoc: Class: Command

# Class: Command

## Command(msgId, name, params)

A command is a request from the client to run a series of remote end steps and return a fitting response.

The command can be synthesised from the message passed over the Marionette socket using the {@code fromMsg} function. The format of a message is:

    [type, id, name, params]

where

type (integer) Must be zero (integer). Zero means that this message is a command.

id (integer) Integer used as a sequence number. The server replies with the same ID for the response.

name (string) String representing the command name with an associated set of remote end steps.

params (JSON Object or null) Object of command function arguments. The keys of this object must be strings, but the values can be arbitrary values.

A command has an associated message {@code id} that prevents the dispatcher from sending responses in the wrong order.

The command may also have optional error- and result handlers that are called when the client returns with a response. These are {@code function onerror({Object})}, {@code function onresult({Object})}, and {@code function onresult({Response})}.

## Constructor

#### new Command(msgId, name, params)

##### Parameters:

Name | Type | Description
--- | --- | ---
`msgId` | number | Message ID unique identifying this message.
`name` | string | Command name.
`params` | Object.<string, ?> | Command parameters.

Source:
  - message.js, line 116

### Methods

#### onresponse(resp)

Calls the error- or result handler associated with this command. This function can be replaced with a custom response handler.

##### Parameters:

Name | Type | Description
--- | --- | ---
`resp` | Response | The response to pass on to the result or error to the {@code onerror} or {@code onresult} handlers to.

Source:
  - message.js, line 137