WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

EmberJS Classes and Instances


Class is a format or blue print, that has a gathering of factors and capacities, where as examples are identified with the object of that class. Making and broadening the Ember class on Ember.Object is the fundamental property of the Ember object display.

Defining Classes

You can make new Ember class by utilizing the Ember.Object's extend() technique −
const test = Ember.Object.extend ({ 

//code here 

});

The above code makes new Ember class called "test" which acquires the properties from initializers, figured properties, and so forth. Subsequent to making the class, you have to make example of it by utilizing the make() technique as appeared underneath −

const state = test.create(); 

Using the above occurrence "state", get to the properties by utilizing the set and get accessor methods.

console.log(state.get('stateOn')); 

You can change the "stateon" property by utilizing the set strategy as appeared beneath −

state.set('stateOn', genuine); 

Initializing Instance

When another occurrence is made, its init strategy is summoned naturally. This is the perfect spot to do setup required on new instances:

App.Person = Ember.Object.extend({ 

init: function() { 

var name = this.get('name'); 

alert(name + ", detailing for duty!"); 

} 

}); 

App.Person.create({ 

name: "Stefan Penner" 

}); 

//cautions "Stefan Penner, announcing for duty!" 

If you are subclassing a system class, as Ember.View or Ember.ArrayController, and you abrogate the init technique, ensure you call this._super()! On the off chance that you don't, the framework might not have an chance to do vital setup work, and you'll see bizarre conduct in your application.

When getting to the properties of an article, utilize the get furthermore, set accessor methods:

 

var individual = App.Person.create(); 

var name = person.get('name'); 

person.set('name', "John Cena "); 

Make beyond any doubt to utilize these accessor techniques; generally, processed properties won't recalculate, onlookers won't fire, and formats won't update.