You can initialize the new instance by invoking the init() method. When declaring objects in
the class, you need to initialize each instance with the init() method.
Example
The following example uses the above mentioned properties and displays an alert message
when an Ember object is initialized:
import Ember from 'ember'; //import ember module
export default function() {
//new ember object
const Demo = Ember.Object.extend({
init(){
alert('The default property of stateOn is : ' + this.get('stateOn'));
},
stateOn: false
});
const state = Demo.create(); //new instance from object with create() method
state.set('stateOn', true);
console.log(state.get('stateOn'));
}
Now open the app.js file and add the following line on top of the file:
import classinstance from './classinstance';
Where, classinstance is a name of the file specified as "classinstance.js" and created under
the "app" folder. Now, call the inherited "classinstance" at the bottom, before the export. This
executes the classinstance function which is created in the classinstance.js file:
classinstance();