function mixin(dst) {
for (var i = 1; i < arguments.length; i++) {
for (var prop in arguments[i]) {
if (arguments[i].hasOwnProperty(prop)) {
dst[prop] = arguments[i][prop];
}
}
}
return dst;
}
Function.prototype.inherit = function(proto) {
var that = this;
proto = proto || {};
var constructor = proto.hasOwnProperty('constructor') ? proto.constructor : function() { that.apply(this, arguments); };
var F = function() {};
F.prototype = this.prototype;
constructor.prototype = mixin(new F(), proto);
constructor.superclass = this.prototype;
constructor.prototype.constructor = constructor;
return constructor;
};
// ===============================================
var A = Object.inherit({
constructor: function(foo) {
this.foo = foo;
},
alert: function() {
alert(this.foo);
}
});
var B = A.inherit({
constructor: function(foo) {
B.superclass.constructor.apply(this, arguments);
this.bar = foo + 1;
},
alert: function() {
B.superclass.alert.apply(this, arguments);
alert(this.bar);
}
});
var b = new B(1);
b.alert();
Например.