I would do just exactly that - explicitly:-
sleep : function(t) {
Animal.prototoype.sleep.call(this, t);
}
Using the YAHOO!'s YUI class-based-inheritance-emulating functions, you
could do (untested)
The OP is interested in understanding how to solve the problem.
The function itself, with my comments interspersed:-
/**
* Utility to set up the prototype, constructor and superclass
properties to
* support an inheritance strategy that can chain constructors and
methods.
* Static members will not be inherited.
*
*
@method extend
* @static
* @param {Function} subc the object to modify
* @param {Function} superc the object to inherit
* @param {Object} overrides additional properties/methods to add
to the
* subclass prototype. These will
override the
* matching items obtained from the
superclass
* if present.
*/
extend: function(subc, superc, overrides) {
if (!superc||!subc) {
// GS: Safe to omit - new - keyword.
throw new Error("extend failed, please check that " +
"all dependencies are included.");
}
var F = function() {};
F.prototype=superc.prototype;
subc.prototype=new F();
subc.prototype.constructor=subc;
subc.superclass=superc.prototype;
// GS: Consider using === (may result in increased performance in
JScript).
if (superc.prototype.constructor ==
Object.prototype.constructor) {
superc.prototype.constructor=superc;
}
if (overrides) {
for (var i in overrides) {
// GS: Important call to hasOwnProperty.
if (L.hasOwnProperty(overrides, i)) {
subc.prototype
=overrides;
}
}
L._IEEnumFix(subc.prototype, overrides);
}
},
Another possibility is to cache the function being new'd. One possible
way to accomplish this is to use the one the Activation object is in -
arguments.callee:-
var f = arguments.callee;
But this requires a check in the - extend - function, which gets
recursed.
if(arguments.length === 0) return;
It's good to see that YAHOO has finally fixed some of the significant
bugs in this code.
Animal = function (a) {
...
}
Animal.prototype.sleep = function (t) {
...
}
Human = function (a) {
Animal.apply (this, arguments);
}
YAHOO.extend (Human, Animal);
Human.prototype.sleep = function (t) {
... // do some stuff
Human.superclass.sleep.call (this, t);
Did you mean:
Human.superclass.prototype.sleep.call(this, t)
- ?
Or more explicit:-
Animal.prototype.sleep.call(this, t);
Garrett