Search code examples
javascriptprototypeparse-platform

Extending prototype function without overwriting it


I need to fix a bug in the save function of the Parse.Object library. However, when I try to call the original save function in my overwritten prototype, it loops recursively until the stack overflows!

Parse.Object.prototype.save = function (arg1, arg2, arg3) {
    fixIncludedParseObjects(this);

    Parse.Object.prototype.save.call(this, arg1, arg2, arg3); // endless loop
};

How can I change the endless loop line to call the original function made by parse?

Thanks!


Solution

  • Try this:

    (function(save) {
      Parse.Object.prototype.save = function (arg1, arg2, arg3) {
        fixIncludedParseObjects(this);
        save.call(this, arg1, arg2, arg3);
      };
    }(Parse.Object.prototype.save));