Answer the question
In order to leave comments, you need to log in
How to be, if callback'y substitute a context (an ordinary and OOP decision)?
function Two(){
One.call(this);
}
Two.prototype = Object.create(One.prototype);
Two.prototype.constructor = Two;
Two.prototype = {
setParams: function(num){
this.prop = num
},
prop: null
}
var two = new Two();
two.setParams(1);
console.log(two.prop);
Answer the question
In order to leave comments, you need to log in
Can you explain this design to me?
function One(){
// Очевидно, устанавливает this свойства и методы
}
function Two(){
One.call(this);
}
Two.prototype = Object.create(One.prototype);
Two.prototype = {
setParams: function (num) {
this.prop = num;
},
prop: null
};
function One(){}
function Two(){}
function F(options) {
for (var i in options) {
if (options.hasOwnProperty(i)) {
this[i] = options[i];
}
}
}
One.prototype = {
// наследуемые свойства и методы
};
F.prototype = One.prototype;
Two.prototype = new F({
setParams: function (num) {
this.prop = num;
},
prop: null
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question