Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js this.super() what is the purpose

Tags:

ember.js

Lot of times i see the function

init: function() {
    return this._super();
  },

What is the purpose of this function and when to use them? Can someone explain to me practically use?

like image 461
user2521436 Avatar asked May 13 '14 22:05

user2521436


People also ask

How does Ember JS work?

Ember uses templates to organize the layout of HTML in an application. Ember templates use the syntax of Handlebars templates. Anything that is valid Handlebars syntax is valid Ember syntax. Here, {{name}} is a property provided by the template's context.

What is an ember model?

In Ember Data, models are objects that represent the underlying data that your application presents to the user. Note that Ember Data models are a different concept than the model method on Routes, although they share the same name.

What is store in Ember JS?

The store contains all of the data for records loaded from the server. It is also responsible for creating instances of Model that wrap the individual data for a record, so that they can be bound to in your Handlebars templates.


1 Answers

Calling this._super() in the init calls the init function of the superclass.

The documentation gives this example:

App.Person = Ember.Object.extend({
  say: function(thing) {
    var name = this.get('name');
    alert(name + " says: " + thing);
  }
});

App.Soldier = App.Person.extend({
  say: function(thing) {
    this._super(thing + ", sir!");
  }
});

var yehuda = App.Soldier.create({
  name: "Yehuda Katz"
});

yehuda.say("Yes"); // alerts "Yehuda Katz says: Yes, sir!"
like image 86
Buck Doyle Avatar answered Nov 15 '22 10:11

Buck Doyle