# PsychObject

## util. PsychObject

PsychoObject is the base class for all PsychoJS objects. It is responsible for handling attributes.

## Constructor

#### new PsychObject(psychoJS, name)

Source:
  - util/PsychObject.js, line 20

##### Parameters:

Name | Type | Description
--- | --- | ---
`psychoJS` | module:core.PsychoJS | the PsychoJS instance
`name` | string | the name of the object (mostly useful for debugging)

### Extends

- EventEmitter

### Members

#### psychoJS

Source:
  - util/PsychObject.js, line 46

Get the PsychoJS instance.

#### psychoJS

Source:
  - util/PsychObject.js, line 56

Setter for the PsychoJS attribute.

### Methods

#### (protected) _addAttribute(name, value, defaultValueopt, onChangeopt)

Source:
  - util/PsychObject.js, line 345

Add an attribute to this instance (e.g. define setters and getters) and affect a value to it.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | string |  | the name of the attribute
`value` | object |  | the value of the attribute
`defaultValue` | object | <optional> | the default value for the attribute
`onChange` | function | <optional> | function called upon changes to the attribute value

#### (protected) _setAttribute(attributeName, attributeValue, logopt, operationopt, stealthopt) → {boolean}

Source:
  - util/PsychObject.js, line 113

Set the value of an attribute.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`attributeName` | string |  |  | the name of the attribute
`attributeValue` | object |  |  | the value of the attribute
`log` | boolean | <optional> | `false` | whether of not to log
`operation` | string | <optional> |  | the binary operation such that the new value of the attribute is the result of the application of the operation to the current value of the attribute and attributeValue
`stealth` | boolean | <optional> | `false` | whether or not to call the potential attribute setters when setting the value of this attribute

##### Returns:

whether or not the value of that attribute has changed (false if the attribute was not previously set)

Type
  boolean

#### emit(name, data) → {boolean}

Source:
  - util/EventEmitter.js, line 115
Overrides:
  - EventEmitter#emit

Emit an event with a given name and associated data.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | the name of the event
`data` | object | the data of the event

##### Returns:

true if at least one listener has been registered for that event, and false otherwise

Type
  boolean

#### off(name, listener)

Source:
  - util/EventEmitter.js, line 96
Overrides:
  - EventEmitter#off

Remove the listener with the given uuid associated to the given event name.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | the name of the event
`listener` | module:util.EventEmitter~Listener | a listener called upon emission of the event

#### on(name, listener)

Source:
  - util/EventEmitter.js, line 49
Overrides:
  - EventEmitter#on

Register a new listener for events with the given name emitted by this instance.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | the name of the event
`listener` | module:util.EventEmitter~Listener | a listener called upon emission of the event

##### Returns:

string - the unique identifier associated with that (event, listener) pair (useful to remove the listener)

#### once(name, listener)

Source:
  - util/EventEmitter.js, line 77
Overrides:
  - EventEmitter#once

Register a new listener for the given event name, and remove it as soon as the event has been emitted.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | the name of the event
`listener` | module:util.EventEmitter~Listener | a listener called upon emission of the event

##### Returns:

string - the unique identifier associated with that (event, listener) pair (useful to remove the listener)

#### toString() → {string}

Source:
  - util/PsychObject.js, line 68

String representation of the PsychObject.

Note: attribute values are limited to 50 characters.

##### Returns:

the representation

Type
  string