Class CoreObject
public| Defined in: | packages/@ember/-internals/runtime/lib/system/core_object.js:147 |
|---|---|
| Module: | @ember/object |
import CoreObject from '@ember/object/core';
CoreObject is the base class for all Ember constructs. It establishes a class system based on Ember's Mixin system, and provides the basis for the Ember Object Model. CoreObject should generally not be used directly, instead you should use EmberObject.
Usage
You can define a class by extending from CoreObject using the extend method:
const Person = CoreObject.extend({
name: 'Tomster',
}); For detailed usage, see the Object Model section of the guides.
Usage with Native Classes
Native JavaScript class syntax can be used to extend from any CoreObject based class:
class Person extends CoreObject {
init() {
super.init(...arguments);
this.name = 'Tomster';
}
} Some notes about class usage:
-
newsyntax is not currently supported with classes that extend fromEmberObjectorCoreObject. You must continue to use thecreatemethod when making new instances of classes, even if they are defined using native class syntax. If you want to usenewsyntax, consider creating classes which do not extend fromEmberObjectorCoreObject. Ember features, such as computed properties and decorators, will still work with base-less classes. - Instead of using
this._super(), you must use standardsupersyntax in native classes. See the MDN docs on classes for more details. - Native classes support using constructors to set up newly-created instances. Ember uses these to, among other things, support features that need to retrieve other entities by name, like Service injection and
getOwner. To ensure your custom instance setup logic takes place after this important work is done, avoid using theconstructorin favor ofinit. - Properties passed to
createwill be available on the instance by the timeinitruns, so any code that requires these values should work at that time. - Using native classes, and switching back to the old Ember Object model is fully supported.
Methods
Properties
Events
No documented items
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/classes/CoreObject