Zrozumienie najwyższej metody wprowadzonej przez Crockforda
W modelu dziedziczenia funkcjonalnego Crockford wprowadza nowysuperior
metoda poprzez:
Object.method('superior', function (name) {
var that = this,
method = that[name];
return function () {
return method.apply(that, arguments);
};
});
Gdziemethod
jest :
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
Przykład:
var coolcat = function (spec) {
var that = cat(spec),
super_get_name = that.superior('get_name');
that.get_name = function (n) {
return 'like ' + super_get_name() + ' baby';
};
return that;
};
Moje pytanie brzmi: Dlaczego po prostu nie przypisujthat.get_name
dosuper_get_name
?