Ember.Comparable Class packages/ember-runtime/lib/mixins/comparable.js:9
Extends: Ember.Mixin
Defined in: packages/ember-runtime/lib/mixins/comparable.js:9
Module: ember-runtime
Implements some standard methods for comparing objects. Add this mixin to any class you create that can compare its instances.
You should implement the compare() method.
apply
(obj)
Parameters:
- obj
Returns:
- applied object
compare
(a, b)
Integer
Override to return the result of the comparison of the two parameters. The compare method should return:
-1ifa < b0ifa == b1ifa > b
Default implementation raises an exception.
Parameters:
- a Object
- the first object to compare
- b Object
- the second object to compare
Returns:
- Integer
- the result of the comparison
create
(arguments)
static
Creates an instance of a class. Accepts either no arguments, or an object containing values to initialize the newly instantiated object with.
1 2 3 4 5 6 7 8 9 10 11 |
App.Person = Ember.Object.extend({
helloWorld: function() {
alert("Hi, my name is " + this.get('name'));
}
});
var tom = App.Person.create({
name: 'Tom Dale'
});
tom.helloWorld(); // alerts "Hi, my name is Tom Dale".
|
create will call the init function if defined during
Ember.AnyObject.extend
If no arguments are passed to create, it will not set values to the new
instance during initialization:
1 2 |
var noName = App.Person.create(); noName.helloWorld(); // alerts undefined |
NOTE: For performance reasons, you cannot declare methods or computed
properties during create. You should instead declare methods and computed
properties when using extend.
Parameters:
- arguments
detect
(obj)
Boolean
Parameters:
- obj
Returns:
- Boolean
reopen
(arguments)
Parameters:
- arguments
isComparable
Boolean
walk like a duck. Indicates that the object can be compared.
Default: true
Fork Us!