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!
Prototyping allows objects to inherit, override, and extend functionality provided by other objects in a similar manner as inheritance, overriding, abstraction, and related technologies do in C#, Java, and other languages. Every object you create in JavaScript has a prototype property by default that can be accessed.
constructor. The constructor property returns a reference to the Object constructor function that created the instance object. Note that the value of this property is a reference to the function itself, not a string containing the function's name.
The answer is Prototype. The prototype is an object that is associated with every functions and objects by default in JavaScript, where function's prototype property is accessible and modifiable and object's prototype property (aka attribute) is not visible. Every function includes prototype object by default.
Similar to accepted answer but maybe a little easier to understand
var originalSaveFn = Parse.Object.prototype.save;
Parse.Object.prototype.save = function(arg1, arg2, arg3) {
fixIncludedParseObjects(this);
originalSaveFn.call(this, arg1, arg2, arg3);
};
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);
Try this:
(function(save) {
Parse.Object.prototype.save = function (arg1, arg2, arg3) {
fixIncludedParseObjects(this);
save.call(this, arg1, arg2, arg3);
};
}(Parse.Object.prototype.save));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With