#

API Docs for: v2.11.1
Show: Inherited Protected Private Deprecated

# Ember.Evented Class

Defined in: `packages/ember-runtime/lib/mixins/evented.js:14`
Module: ember-runtime
Parent Module: ember

This mixin allows for Ember objects to subscribe to and emit events.

    App.Person = Ember.Object.extend(Ember.Evented, {
      greet: function() {
        // ...
        this.trigger('greet');
      }
    });

    var person = App.Person.create();

    person.on('greet', function() {
      console.log('Our person has greeted');
    });

    person.greet();

    // outputs: 'Our person has greeted'

You can also chain multiple event subscriptions:

    person.on('greet', function() {
      console.log('Our person has greeted');
    }).one('greet', function() {
      console.log('Offer one-time special');
    }).off('event', this, forgetThis);

- Index
- Methods

## Item Index

### Methods

- has
- off
- on
- one
- trigger

## Methods

### `has`

(

- `name`

)
Boolean public

Defined in `packages/ember-runtime/lib/mixins/evented.js:142`

Checks to see if object has any subscriptions for named event.

#### Parameters:

- `name` String

  The name of the event

#### Returns:

Boolean:

does the object have a subscription for event

### `off`

(

- `name`
- `target`
- `method`

)
public

Defined in `packages/ember-runtime/lib/mixins/evented.js:127`

Cancels subscription for given name, target, and method.

#### Parameters:

- `name` String

  The name of the event

- `target` Object

  The target of the subscription

- `method` Function

  The function of the subscription

#### Returns:

this

### `on`

(

- `name`
- `[target]`
- `method`

)
public

Defined in `packages/ember-runtime/lib/mixins/evented.js:52`

Subscribes to a named event with given function.

    person.on('didLoad', function() {
      // fired once the person has loaded
    });

An optional target can be passed in as the 2nd argument that will be set as the "this" for the callback. This is a good way to give your function access to the object triggering the event. When the target parameter is used the callback becomes the third argument.

#### Parameters:

- `name` String

  The name of the event

- `[target]` Object optional

  The "this" binding for the callback

- `method` Function

  The callback to execute

#### Returns:

this

### `one`

(

- `name`
- `[target]`
- `method`

)
public

Defined in `packages/ember-runtime/lib/mixins/evented.js:78`

Subscribes a function to a named event and then cancels the subscription after the first time the event is triggered. It is good to use `one` when you only care about the first time an event has taken place.

This function takes an optional 2nd argument that will become the "this" value for the callback. If this argument is passed then the 3rd argument becomes the function.

#### Parameters:

- `name` String

  The name of the event

- `[target]` Object optional

  The "this" binding for the callback

- `method` Function

  The callback to execute

#### Returns:

this

### `trigger`

(

- `name`
- `args`

)
public

Defined in `packages/ember-runtime/lib/mixins/evented.js:104`

Triggers a named event for the object. Any additional arguments will be passed as parameters to the functions that are subscribed to the event.

    person.on('didEat', function(food) {
      console.log('person ate some ' + food);
    });

    person.trigger('didEat', 'broccoli');

    // outputs: person ate some broccoli

#### Parameters:

- `name` String

  The name of the event

- `args` Object...

  Optional arguments to pass on