JSFiddle - React, Tailwind, and code Playground
by dmelnik
JavaScript
var A = function() {
this.param1 = 'string1';
this.param2 = 'string2';
this.test = function() {
console.log('prototype test');
}
};
// Создаём новый экземпляр конструктора
var B = function() {
var self = this;
A.apply(self, arguments);
self.prototype = new A();
self.constructor = B;
}
var b = new B(), a = new A();
// Переопределяем свойства и методы
b.param1 = 'riba';
b.test = function() {
// Сделать что-нибудь.
console.log('test')
// Вызываем метод родителя и возвращаем его результат
return this.prototype.test.apply(this, arguments);
}
a.test();
b.test();