# Class: BaseObject

This documentation is for OpenLayers v10.9.0. The latest is v.

## ol/Object~BaseObject

    import BaseObject from 'ol/Object.js';

Abstract base class; normally only used for creating subclasses and not instantiated in apps. Most non-trivial classes inherit from this.

This extends `Observable` with observable properties, where each property is observable as well as the object as a whole.

Classes that inherit from this have pre-defined properties, to which you can add your owns. The pre-defined properties are listed in this documentation as 'Observable Properties', and have their own accessors; for example, `Map` has a `target` property, accessed with `getTarget()` and changed with `setTarget()`. Not all properties are however settable. There are also general-purpose accessors `get()` and `set()`. For example, `get('target')` is equivalent to `getTarget()`.

The `set` accessors trigger a change event, and you can monitor this by registering a listener. For example, `View` has a `center` property, so `view.on('change:center', function(evt) {...});` would call the function whenever the value of the center property changes. Within the function, `evt.target` would be the view, so `evt.target.getCenter()` would return the new center.

You can add your own observable properties with `object.set('prop', 'value')`, and retrieve that with `object.get('prop')`. You can listen for changes on that property value with `object.on('change:prop', listener)`. You can get a list of all properties with `getProperties`.

Note that the observable properties are separate from standard JS properties. You can, for example, give your map object a title with `map.title='New title'` and with `map.set('title', 'Another title')`. The first will be a `hasOwnProperty`; the second will appear in `getProperties()`. Only the second is observable.

Properties can be deleted by using the unset method. E.g. object.unset('foo').

#### new BaseObject(values)

Object.js, line 91

  Name | Type | Description
  --- | --- | ---
  `values` | NoInfer.<Properties> | undefined | An object with key-value pairs.

  ##### Fires:

  - `change` (BaseEvent) - Generic change event. Triggered when the revision counter is increased.
  - `error` (BaseEvent) - Generic error event. Triggered when an error occurs.
  - `propertychange` (ObjectEvent) - Triggered when a property is changed.

### Subclasses

- Collection
- Feature
- Geolocation
- Map
- Overlay
- View
- Control
- Geometry
- Interaction
- BaseLayer
- Source

### Extends

- Observable

### Methods

#### changed() inherited

Observable.js, line 68

  Increases the revision counter and dispatches a 'change' event.

#### dispatchEvent(event){boolean | undefined} inherited

events/Target.js, line 85

  Dispatches an event and calls all listeners listening for events of this type. The event parameter can either be a string or an Object with a `type` property.

  Name | Type | Description
  --- | --- | ---
  `event` | BaseEvent | string | Event object.

  ##### Returns:

  `false` if anyone called preventDefault on the event object or if any of the listeners returned false.

#### get(key){*}

Object.js, line 136

  Gets a value.

  Name | Type | Description
  --- | --- | ---
  `key` | string | Key name.

  ##### Returns:

  Value.

#### getKeys(){Array.<string>}

Object.js, line 149

  Get a list of object property names.

  ##### Returns:

  List of property names.

#### getProperties(){NoInfer.<Properties>}

Object.js, line 158

  Get an object of all property names and values.

  ##### Returns:

  Object.

#### getRevision(){number} inherited

Observable.js, line 79

  Get the version number for this object. Each time the object is modified, its version number will be incremented.

  ##### Returns:

  Revision.

#### on(type, listener){EventsKey | Array<EventsKey>} inherited

Observable.js, line 152

  Listen for a certain type of event.

  Name | Type | Description
  --- | --- | ---
  `type` | string | Array.<string> | The event type or array of event types.
  `listener` | function | The listener function.

  ##### Returns:

  Unique key for the listener. If called with an array of event types as the first argument, the return will be an array of keys.

#### once(type, listener){EventsKey | Array<EventsKey>} inherited

Observable.js, line 164

  Listen once for a certain type of event.

  Name | Type | Description
  --- | --- | ---
  `type` | string | Array.<string> | The event type or array of event types.
  `listener` | function | The listener function.

  ##### Returns:

  Unique key for the listener. If called with an array of event types as the first argument, the return will be an array of keys.

#### set(key, value, silent)

Object.js, line 218

  Sets a value.

  Name | Type | Description
  --- | --- | ---
  `key` | string | Key name.
  `value` | * | Value.
  `silent` | boolean | undefined | Update without triggering an event.

#### setProperties(values, silent)

Object.js, line 238

  Sets a collection of key-value pairs. Note that this changes any existing properties and adds new ones (it does not remove any existing properties).

  Name | Type | Description
  --- | --- | ---
  `values` | Partial.<NoInfer.<Properties>> | Values.
  `silent` | boolean | undefined | Update without triggering an event.

#### un(type, listener) inherited

Observable.js, line 173

  Unlisten for a certain type of event.

  Name | Type | Description
  --- | --- | ---
  `type` | string | Array.<string> | The event type or array of event types.
  `listener` | function | The listener function.

#### unset(key, silent)

Object.js, line 262

  Unsets a property.

  Name | Type | Description
  --- | --- | ---
  `key` | string | Key name.
  `silent` | boolean | undefined | Unset without triggering an event.