Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!

function inheritePrototype(child, _super) {
var __inheritance = function () {};
__inheritance.prototype = _super.prototype;
child._super = _super;
child.prototype = new __inheritance();
child.prototype.constructor = child;
}
// пример
function A() {
this.state = 10;
}
A.prototype.test = function () {
alert('A.test');
};
function B() {
B._super.apply(this, arguments);
}
inheritePrototype(B, A);
B.prototype.test = function () {
B._super.prototype.test.apply(this, arguments);
alert('B.test');
};
var b = new B();
b.test();
alert(b.state);
B._super.prototype.test.apply(this, arguments); — некрасиво и неудобно, я сам когда-то так делал. Гораздо удобнее писать this.__base() для всех методов, а не думать постоянно о том, кто базовый класс и писать эту длинную однообразную простыню. var Test = $.inherit(
{
__constructor: function() {
$('body').on('click', 'a', this.onLinkClick);
// or
// var self = this;
// $('body').on('click', 'a', $.proxy(this.onLinkClick, this));
},
onLinkClick: function() {
? доступ к this Test
? доступ к this 'a'
return false;
}
});
Плагин для jQuery, реализующий наследование