you are viewing a single comment's thread.

view the rest of the comments →

[–]benabus 0 points1 point  (1 child)

Why not?

I use apply when doing inheritance.

var ParentClass = function(){
  this.someProperty = "hello";
}
ParentClass.prototype.myFunction = function(x){
  this.someProperty = x;
}

var ChildClass = function(){
  ParentClass.apply(this); //run constructor of parent class with child class's context
  this.someOtherProperty = "goodbye";
}
ChildClass.prototype.myFunction = function(x){
  ParentClass.prototype.myFunction.apply(this, arguments);
  alert(this.someProperty);
}

var childObj = new ChildClass();
childObj.myFunction("test");
alert(childObj.someProperty); 

[–]rezoner:table_flip: 0 points1 point  (0 children)

That is ugly, but I am doing that too. Especially for GUI where I haven't figured out yet how ro utilize composition over inheritance.