According to Crockford, the best practice is NOT using this pointer due to security issues.
I found this in the Ember guide,
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"); // alerts "Yehuda Katz says: Yes, sir!"
How can this be avoided in such code situations?
Aucun commentaire:
Enregistrer un commentaire