Going through the example code for chapter 5.4 in Javascript: The Good Parts, the following is used to demonstrate the use of the functional pattern to call super methods:
Object.method('superior', function (name) {
var that = this, method = that[name];
return function () {
return method.apply(that, arguments);
};
});
This would be used as follows (where "cat" is another constructor function that has a 'get_name' function defined) :
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;
};
However when running the sample code, F12 tools show the following:
Uncaught TypeError: Object function Object() { [native code] } has no method 'method'.
What am I missing here?