И двете родителски функции се заместват от дъщерен. две в детето се обажда на родителя две. обаче очаквах, че на ниво родител извикването на един ще извика метода на детето. Има ли концепция, която пропускам?
Благодаря ви предварително!
function parent(){}
parent.prototype.one = function(){
$('body').append("Parent: one <br/>");
}
parent.prototype.two = function(){
this.one();
$('body').append("Parent: two <br/>");
}
function child(){}
child.prototype = new parent();
child.prototype.constructor = child;
child.prototype.one = function(){ //should this function not be called?
$('body').append('Child: one <br />');
}
child.prototype.two = function(){
$('body').append('Child: do some child stuff here and call parent: <br />');
parent.prototype.two();
}
var k = new child();
k.two();
this.one()
се обажда наparent.prototype.one()
вtwo()
на вашето дете, защотоthis
еparent.prototype
- person Joe Simmons   schedule 26.09.2013child.prototype.one()
? Не съм сигурен какво всъщност се опитвате да направите. За какво е всичко това? - person Joe Simmons   schedule 26.09.2013parent.prototype.two.call(this)
? - person slebetman   schedule 26.09.2013one
приthis
верига от прототипи, а това еchild.prototype.one.
this` е обект от прототипитеchild.prototype
от прототипитеparent.prototype
- person A. Matías Quezada   schedule 27.09.2013this.one()
се обажда наparent.prototype.one
при дететоtwo()
, защотоthis
еparent.prototype
. Това не е вярно,this
е обект от прототипитеchild.prototype
, така чеthis.one
препраща къмchild.prototype.one
- person A. Matías Quezada   schedule 28.09.2013parent.prototype.two()
'това' ще бъдеparent.prototype
- person Joe Simmons   schedule 29.09.2013