| Module: | @ember/object |
|---|
Defined in packages/@ember/-internals/metal/lib/properties.ts:13
import { defineProperty } from '@ember/object'; 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 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.
import { defineProperty, computed } from '@ember/object';
// ES5 compatible mode
defineProperty(contact, 'firstName', {
writable: true,
configurable: false,
enumerable: true,
value: 'Charles'
});
// define a simple property
defineProperty(contact, 'lastName', undefined, 'Jolley');
// define a computed property
defineProperty(contact, 'fullName', computed('firstName', 'lastName', function() {
return this.firstName+' '+this.lastName;
}));
© 2022 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/4.9/functions/@ember%2Fobject/defineProperty