Friday, 9 December 2011

js extend method

this is what you need to use if you want to extend a function in js. Easy to use :).

// to use only for alert
Function.prototype.extend = function (fn) {
    var self = this;
 return function () {
  //console.log(self)
  //console.log(fn)
        try{
   var returnValue1 = self(arguments[0]);
   }catch(e){}
  try{
   var returnValue2 = fn(arguments[0]);
   }catch(e){}

        return returnValue1 && returnValue2;
    };
};

No comments:

Post a Comment