defineProperty (obj, keyName, desc, data) private
NOTE: This is a low-level method used by other parts of the API. You almost never want to call this method directly. Instead you should use Ember.mixin()
to define new properties.
Defines a property on an object. This method works much like the ES5 Object.defineProperty()
method except that it can also accept computed properties and other special descriptors.
Normally this method takes only three parameters. However if you pass an instance of Descriptor
as the third param then you can pass an optional value as the fourth parameter. This is often more efficient than creating new descriptor hashes for each property.
Examples
// ES5 compatible mode Ember.defineProperty(contact, 'firstName', { writable: true, configurable: false, enumerable: true, value: 'Charles' }); // define a simple property Ember.defineProperty(contact, 'lastName', undefined, 'Jolley'); // define a computed property Ember.defineProperty(contact, 'fullName', Ember.computed('firstName', 'lastName', function() { return this.firstName+' '+this.lastName; }));
Parameters:
-
obj
Object
- the object to define this property on. This may be a prototype.
-
keyName
String
- the name of the property
-
desc
[Descriptor]
- an instance of `Descriptor` (typically a computed property) or an ES5 descriptor. You must provide this or `data` but not both.
-
data
[*]
- something other than a descriptor, that will become the explicit value of this property.
Please login to continue.