Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call base method in Javascript using Douglas Crockford's functional inheritance

Basically how do I call a base method using this patter below?

var GS = {};
GS.baseClass = function (somedata) {
  var that = {};
  that.data = somedata;

  //Base class method
  that.someMethod = function(somedata) {
    alert(somedata);
  };

  return that;
};

GS.derivedClass = function(somedata) {
 var that = GS.baseClass(somedata);

 //Overwriting base method
 that.someMethod = function(somedata) {
   //How do I call base method from here? 

   //do something else
 };
 return that;
};

Thanks.

like image 298
Sergey Avatar asked Sep 23 '09 18:09

Sergey


1 Answers

var GS = {};
GS.baseClass = function (somedata) {
  var that = {};
  that.data = somedata;

  //Base class method
  that.someMethod = function(somedata) {
    alert(somedata);
  };

  return that;
};

GS.derivedClass = function(somedata) {
 var that = GS.baseClass(somedata);

 //Overwriting base method
 var basemethod = that.someMethod;
 that.someMethod = function(somedata) {
   //How do I call base method from here? 
   basemethod.apply(that, [somedata]);
   //do something else
 };
 return that;
};

Cheers.

like image 152
Anatoliy Avatar answered Oct 11 '22 00:10

Anatoliy