0

I'm trying to learn Ember framework and I found this sample code in the Ember documentation.I'm new to JavaScript and please help me to understand how the following output was received.

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

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

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

yehuda.say("Yes");

output: alerts "Yehuda Katz says: Yes, sir!"

The problem with me is how the say function in Person class got executed because it has been overridden in the Soldier class below.I'm some what stuck in method calling in here.And what does the super keyword does there. Thank you

documentation: https://guides.emberjs.com/v1.11.0/object-model/

Lux
  • 17,835
  • 5
  • 43
  • 73
BenSV
  • 139
  • 4
  • 13
  • becuase u are calling.. `this._super`, you have overridden but calling super – xdeepakv May 17 '20 at 05:37
  • Does this answer your question? [JavaScript override methods](https://stackoverflow.com/questions/6885404/javascript-override-methods) – Joundill May 17 '20 at 05:38
  • 4
    Just want to note that the documentation you're looking at for v1.11 is quite old. Javascript as a language has advanced substantially since then. In particular while early Ember needed it's own EmberObject model these concepts are now part of javascript directly as ESClasses (and other new features). If you're working with an old project, these docs are still valuable, but for "learning ember" and javascript spending time on these concepts probably won't advance your learning very much and may hold you back as the problems they are meant to address no longer exist. – jrjohnson May 17 '20 at 05:42
  • 1
    Indeed. ember `1.11` is basically from 2013. – Lux May 17 '20 at 17:41
  • I suggest to do this tutorial if you are new to Ember. It's for modern Ember, and it's designed to be easier for beginners than the 2013 materials. https://guides.emberjs.com/release/tutorial/part-1/ – handlebears May 22 '20 at 12:29

0 Answers0