10

我需要修复saveParse.Object 库的功能中的错误。但是,当我尝试save在覆盖的原型中调用原始函数时,它会递归循环直到堆栈溢出!

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

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

如何更改无限循环线以调用解析生成的原始函数?

谢谢!

4

3 回答 3

24

试试这个:

(function(save) {
  Parse.Object.prototype.save = function (arg1, arg2, arg3) {
    fixIncludedParseObjects(this);
    save.call(this, arg1, arg2, arg3);
  };
}(Parse.Object.prototype.save));
于 2012-07-08T07:35:28.937 回答
8

类似于接受的答案,但可能更容易理解

var originalSaveFn = Parse.Object.prototype.save;
Parse.Object.prototype.save = function(arg1, arg2, arg3) {
    fixIncludedParseObjects(this);
    originalSaveFn.call(this, arg1, arg2, arg3);
};
于 2018-01-19T13:51:31.960 回答
7
Parse.Object.prototype.save = function (save) {
    return function () {
        fixIncludedParseObjects(this);
        //Remember to return and .apply arguments when proxying
        return save.apply(this, arguments);
    };
}(Parse.Object.prototype.save);
于 2012-07-08T07:48:44.170 回答