samedi 16 mai 2020

How to override JavaScript methods

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/




Aucun commentaire:

Enregistrer un commentaire