Class Ember

public

This namespace contains all Ember methods and functions. Future versions of Ember may overwrite this namespace and therefore, you should avoid adding any new properties.

You can also use the shorthand Em instead of Ember.

At the heart of Ember is Ember-Runtime, a set of core functions that provide cross-platform compatibility and object property observing. Ember-Runtime is small and performance-focused so you can use it alongside other cross-platform libraries such as jQuery. For more details, see Ember-Runtime.

Show:

Module: ember

Alias for jQuery

Module: ember
returns
Ember.NativeArray

Creates an Ember.NativeArray from an Array like object. Does not modify the original object. Ember.A is not needed if Ember.EXTEND_PROTOTYPES is true (the default value). However, it is recommended that you use Ember.A when creating addons for ember or when you can not guarantee that Ember.EXTEND_PROTOTYPES will be true.

Example

var Pagination = Ember.CollectionView.extend({
  tagName: 'ul',
  classNames: ['pagination'],

  init: function() {
    this._super.apply(this, arguments);
    if (!this.get('content')) {
      this.set('content', Ember.A());
    }
  }
});
Module: ember
returns
Object

An empty function useful for some operations. Always returns this.

Module: ember
obj
eventName
String
target
Object|Function

A target object or a function

method
Function|String

A function or the name of a function to be called on target

once
Boolean

A flag whether a function should only be called once

Add an event listener

Module: ember
obj
_path
String
target
Object|Function
method
Function|String
Module: ember
desc
String

A description of the assertion. This will become the text of the Error thrown if the assertion fails.

test
Boolean|Function

Must be truthy for the assertion to pass. If falsy, an exception will be thrown. If this is a function, it will be executed and its return value will be used as condition.

Define an assertion that will throw an exception if the condition is not met. Ember build tools will remove any calls to Ember.assert() when doing a production build. Example:

// Test for truthiness
Ember.assert('Must pass a valid object', obj);

// Fail unconditionally
Ember.assert('This code path should never be run');
Module: ember
obj
Object

The root object of the transform.

to
String

The path to the 'to' side of the binding. Must be relative to obj.

from
String

The path to the 'from' side of the binding. Must be relative to obj or a global path.

returns
Ember.Binding

binding instance

Global helper method to create a new binding. Just pass the root object along with a to and from path to create and connect the binding.

Module: ember
obj
Object

the object whose property you want to check

key
String

the name of the property whose cached value you want to return

returns
Object

the cached value

Returns the cached value for a property, if one exists. This can be useful for peeking at the value of a computed property that is generated lazily, without accidentally causing it to be created.

Module: ember
obj
Object

The object to clone

deep
Boolean

If true, a deep copy of the object is made

returns
Object

The cloned object

Creates a clone of the passed object. This function can take just about any type of object and create a clone of it, including primitive values (which are not actually cloned because they are immutable).

If the passed object implements the copy() method, then this function will simply call that method and return the result. Please see Ember.Copyable for further details.

Module: ember

Available since v1.8.0

Identical to Object.create(). Implements if not available natively.

Module: ember
message
String

A debug message to display.

Display a debug notice. Ember build tools will remove any calls to Ember.debug() when doing a production build.

Ember.debug('I\'m a debug notice!');
Module: ember
message
String

A description of the deprecation.

test
Boolean|Function

An optional boolean. If falsy, the deprecation will be displayed. If this is a function, it will be executed and its return value will be used as condition.

options
Object

An optional object that can be used to pass in a url to the transition guide on the emberjs.com website, and a unique id for this deprecation. The id can be used by Ember debugging tools to change the behavior (raise, log or silence) for that specific deprecation. The id should be namespaced by dots, e.g. "view.helper.select".

Display a deprecation warning with the provided message and a stack trace (Chrome and Firefox only). Ember build tools will remove any calls to Ember.deprecate() when doing a production build.

Module: ember
obj
Object

The object to retrieve from.

keyName
String

The property key to retrieve

returns
Object

the property value or null.

Gets the value of a property on an object. If the property is computed, the function will be invoked. If the property is not defined but the object implements the unknownProperty method then that will be invoked.

If you plan to run on IE8 and older browsers then you should use this method anytime you want to retrieve a property on an object that you don't know for sure is private. (Properties beginning with an underscore '_' are considered private.)

On all newer browsers, you only need to use this method to retrieve properties if the property might not be defined on the object and you want to respect the unknownProperty handler. Otherwise you can ignore this method.

Note that if the object itself is undefined, this method will throw an error.

Module: ember
obj
Object
list
String...|Array

of keys to get

returns
Object

To get multiple properties at once, call Ember.getProperties with an object followed by a list of strings or an array:

Ember.getProperties(record, 'firstName', 'lastName', 'zipCode');
// { firstName: 'John', lastName: 'Doe', zipCode: '10011' }

is equivalent to:

Ember.getProperties(record, ['firstName', 'lastName', 'zipCode']);
// { firstName: 'John', lastName: 'Doe', zipCode: '10011' }
Module: ember
obj
Object

The object to test

returns
Boolean

true if the passed object is an array or Array-like

Returns true if the passed object is an array or Array-like.

Ember Array Protocol:

  • the object has an objectAt property
  • the object is a native Array
  • the object is an Object, and has a length property

Unlike Ember.typeOf this method returns true even if the passed object is not formally array but appears to be array-like (i.e. implements Ember.Array)

Ember.isArray();                                          // false
Ember.isArray([]);                                        // true
Ember.isArray(Ember.ArrayProxy.create({ content: [] }));  // true
Module: ember

Available since v1.5.0

obj
Object

Value to test

returns
Boolean

A value is blank if it is empty or a whitespace string.

Ember.isBlank();                // true
Ember.isBlank(null);            // true
Ember.isBlank(undefined);       // true
Ember.isBlank('');              // true
Ember.isBlank([]);              // true
Ember.isBlank('\n\t');          // true
Ember.isBlank('  ');            // true
Ember.isBlank({});              // false
Ember.isBlank('\n\t Hello');    // false
Ember.isBlank('Hello world');   // false
Ember.isBlank([1,2,3]);         // false
Module: ember
obj
Object

Value to test

returns
Boolean

Verifies that a value is null or an empty string, empty array, or empty function.

Constrains the rules on Ember.isNone by returning true for empty string and empty arrays.

Ember.isEmpty();                // true
Ember.isEmpty(null);            // true
Ember.isEmpty(undefined);       // true
Ember.isEmpty('');              // true
Ember.isEmpty([]);              // true
Ember.isEmpty({});              // false
Ember.isEmpty('Adam Hawkins');  // false
Ember.isEmpty([0,1,2]);         // false
Module: ember
a
Object

first object to compare

b
Object

second object to compare

returns
Boolean

Compares two objects, returning true if they are logically equal. This is a deeper comparison than a simple triple equal. For sets it will compare the internal objects. For any other object that implements isEqual() it will respect that method.

Ember.isEqual('hello', 'hello');  // true
Ember.isEqual(1, 2);              // false
Ember.isEqual([4, 2], [4, 2]);    // false
Module: ember
obj
Object

Value to test

returns
Boolean

Returns true if the passed value is null or undefined. This avoids errors from JSLint complaining about use of ==, which can be technically confusing.

Ember.isNone();              // true
Ember.isNone(null);          // true
Ember.isNone(undefined);     // true
Ember.isNone('');            // false
Ember.isNone([]);            // false
Ember.isNone(function() {});  // false
Module: ember

Available since v1.8.0

obj
Object

Value to test

returns
Boolean

A value is present if it not isBlank.

Ember.isPresent();                // false
Ember.isPresent(null);            // false
Ember.isPresent(undefined);       // false
Ember.isPresent(false);           // false
Ember.isPresent('');              // false
Ember.isPresent([]);              // false
Ember.isPresent('\n\t');          // false
Ember.isPresent('  ');            // false
Ember.isPresent({});              // true
Ember.isPresent('\n\t Hello');    // true
Ember.isPresent('Hello world');   // true
Ember.isPresent([1,2,3]);         // true
Module: ember
original
Object

The object to merge into

updates
Object

The object to copy properties from

returns
Object

Merge the contents of two objects together into the first object.

Ember.merge({first: 'Tom'}, {last: 'Dale'}); // {first: 'Tom', last: 'Dale'}
var a = {first: 'Yehuda'};
var b = {last: 'Katz'};
Ember.merge(a, b); // a == {first: 'Yehuda', last: 'Katz'}, b == {last: 'Katz'}
Module: ember
eventNames
String
func
Function
returns

func

Define a property as a function that should be executed when a specified event or events are triggered.

var Job = Ember.Object.extend({
  logCompleted: Ember.on('completed', function() {
    console.log('Job completed!');
  })
});

var job = Job.create();

Ember.sendEvent(job, 'completed'); // Logs 'Job completed!'
Module: ember
obj
Object

The root object of the transform.

to
String

The path to the 'to' side of the binding. Must be relative to obj.

from
String

The path to the 'from' side of the binding. Must be relative to obj or a global path.

returns
Ember.Binding

binding instance

Module: ember
obj
eventName
String
target
Object|Function

A target object or a function

method
Function|String

A function or the name of a function to be called on target

Remove an event listener

Arguments should match those passed to Ember.addListener.

Module: ember
obj
path
String
target
Object|Function
method
Function|String
Module: ember

Available since v1.5.0

func
Function

The function to be executed.

Run a function meant for debugging. Ember build tools will remove any calls to Ember.runInDebug() when doing a production build.

Ember.runInDebug(() => {
  Ember.Component.reopen({
    didInsertElement() {
      console.log("I'm happy");
    }
  });
});
Module: ember
obj
eventName
String
params
Array

Optional parameters for each listener.

actions
Array

Optional array of actions (listeners).

returns

true

Send an event. The execution of suspended listeners is skipped, and once listeners are removed. A listener without a target is executed on the passed object. If an array of actions is not passed, the actions stored on the passed object are invoked.

Module: ember
obj
Object

The object to modify.

keyName
String

The property key to set

value
Object

The value to set

returns
Object

the passed value.

Sets the value of a property on an object, respecting computed properties and notifying observers and other listeners of the change. If the property is not defined but the object implements the setUnknownProperty method then that will be invoked as well.

Module: ember
obj
properties
Object
returns

obj

Set a list of properties on an object. These properties are set inside a single beginPropertyChanges and endPropertyChanges batch, so observers will be buffered.

var anObject = Ember.Object.create();

anObject.setProperties({
  firstName: 'Stanley',
  lastName: 'Stuart',
  age: 21
});
Module: ember
obj
Object

The object to check for the method

methodName
String

The method name to check for

args
Array

The arguments to pass to the method

returns
*

the return value of the invoked method or undefined if it cannot be invoked

Checks to see if the methodName exists on the obj, and if it does, invokes it with the arguments passed.

var d = new Date('03/15/2013');

Ember.tryInvoke(d, 'getTime');              // 1363320000000
Ember.tryInvoke(d, 'setFullYear', [2014]);  // 1394856000000
Ember.tryInvoke(d, 'noSuchMethod', [2014]); // undefined
Module: ember
root
Object

The object to modify.

path
String

The property path to set

value
Object

The value to set

Error-tolerant form of Ember.set. Will not blow up if any part of the chain is undefined, null, or destroyed.

This is primarily used when syncing bindings, which may try to update after an object has been destroyed.

Module: ember
item
Object

the item to check

returns
String

the type

Returns a consistent type for the passed item.

Use this instead of the built-in typeof to get the type of an item. It will return the same result across all browsers and includes a bit more detail. Here is what will be returned:

| Return Value  | Meaning                                              |
|---------------|------------------------------------------------------|
| 'string'      | String primitive or String object.                   |
| 'number'      | Number primitive or Number object.                   |
| 'boolean'     | Boolean primitive or Boolean object.                 |
| 'null'        | Null value                                           |
| 'undefined'   | Undefined value                                      |
| 'function'    | A function                                           |
| 'array'       | An instance of Array                                 |
| 'regexp'      | An instance of RegExp                                |
| 'date'        | An instance of Date                                  |
| 'class'       | An Ember class (created using Ember.Object.extend()) |
| 'instance'    | An Ember object instance                             |
| 'error'       | An instance of the Error object                      |
| 'object'      | A JavaScript object not inheriting from Ember.Object |

Examples:

Ember.typeOf();                       // 'undefined'
Ember.typeOf(null);                   // 'null'
Ember.typeOf(undefined);              // 'undefined'
Ember.typeOf('michael');              // 'string'
Ember.typeOf(new String('michael'));  // 'string'
Ember.typeOf(101);                    // 'number'
Ember.typeOf(new Number(101));        // 'number'
Ember.typeOf(true);                   // 'boolean'
Ember.typeOf(new Boolean(true));      // 'boolean'
Ember.typeOf(Ember.makeArray);        // 'function'
Ember.typeOf([1, 2, 90]);             // 'array'
Ember.typeOf(/abc/);                  // 'regexp'
Ember.typeOf(new Date());             // 'date'
Ember.typeOf(Ember.Object.extend());  // 'class'
Ember.typeOf(Ember.Object.create());  // 'instance'
Ember.typeOf(new Error('teamocil'));  // 'error'

// 'normal' JavaScript object
Ember.typeOf({ a: 'b' });             // 'object'
Module: ember
message
String

A warning to display.

test
Boolean

An optional boolean. If falsy, the warning will be displayed.

Display a warning with the provided message. Ember build tools will remove any calls to Ember.warn() when doing a production build.