Answer the question
In order to leave comments, you need to log in
How to properly create a function that creates classes?
There is such an idea: to create components (classes) with a specific function. This is how the class creation interface should look like:
Component.create('ComponentName', {
init: function () {}
..... и прочие методы
});
Component.create = function (name, methods) {
var NewClass = function (/*arguments*/) {
// тут записываем в свойства класса переданные при создании экземпляра аргументы и инициализируем:
this.init();
};
// В прототип новой функции записываем
// свойства объекта Component, переданные методы и имя класса
// (просто свойство для наглядности):
NewClass.prototype = Object.create($.extend(this, methods, {
componentName: name
}));
// А затем сохраняем ссылку на функцию в некоем объекте obj = {}, который находится снаружи:
obj[name] = NewClass;
return NewClass;
};
Answer the question
In order to leave comments, you need to log in
try this
NewClass.prototype = Object.create($.extend({}, this, methods, {
componentName: name
}));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question