Answer the question
In order to leave comments, you need to log in
JavaScript: How to correctly implement the ability to "replace/replace" a constructor in a class when it is created and inherited?
Good afternoon.
There is a self-written library for creating and inheriting classes ( code on pastebin ) (the code below shows the creation of a class from a set of parameters / functions) .
var newClass = classConstructor; // Функция - конструктор
// Проходим по списку функция и прописываем их в создаваемый класс
...
var newClass = function( )
{
var callArguments = ( arguments.length > 0 ? arguments : arguments.callee.caller.arguments );
this[ '___con' ].apply( this, callArguments );
};
newClass.prototype.___con = classConstructor;
Answer the question
In order to leave comments, you need to log in
If I understand correctly, then:
function Figure(name) {
this._name = name;
}
Figure.prototype.getName = function () {
return this._name;
};
// проксируем
function WrapFigure(name) {
var obj = Object.create(Figure.prototype);
Figure.apply(obj, arguments);
// что-то делаем
return obj;
}
// проверяем
var cir = new WrapFigure('Circle');
var name = cir.getName();
console.log(name);
// все работает!
arguments calleehighly discouraged, tk. does not work in 'use strict'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question