# call-function Current version: current-plugin-version. [See version history](https://github.com/jspsych/jsPsych/blob/main/packages/plugin-call-function/CHANGELOG.md). This plugin executes a specified function. This allows the experimenter to run arbitrary code at any point during the experiment. The function cannot take any arguments. If arguments are needed, then an anonymous function should be used to wrap the function call (see examples below). ## Parameters In addition to the [parameters available in all plugins](../overview/plugins.md#parameters-available-in-all-plugins), this plugin accepts the following parameters. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable. Parameter | Type | Default Value | Description ----------|------|---------------|------------ func | function | *undefined* | The function to call. async | boolean | `false` | Set to true if `func` is an asynchoronous function. If this is true, then the first argument passed to `func` will be a callback that you should call when the async operation is complete. You can pass data to the callback. See example below. ## Data Generated In addition to the [default data collected by all plugins](../overview/plugins.md#data-collected-by-all-plugins), this plugin collects the following data for each trial. Name | Type | Value -----|------|------ value | any | The return value of the called function. ## Install Using the CDN-hosted JavaScript file: ```js ``` Using the JavaScript file downloaded from a GitHub release dist archive: ```js ``` Using NPM: ``` npm install @jspsych/plugin-call-function ``` ```js import callFunction from '@jspsych/plugin-call-function'; ## Examples ???+ example "Calling a simple function" === "Code" ```javascript var myfunc = function() { return 'you called?'; } var trial = { type: jsPsychCallFunction, func: myfunc } ``` === "Demo"