Zampano Posted May 4, 2018 Share Posted May 4, 2018 Hey everyone, I want to attach some additional code to Phaser.Tween.start. I realize I could do Phaser.Tween.prototype.start_custom = function () { console.log("Custom Code"); Phaser.Tween.prototype.start.call(); } But couldn't I also do it without creating a separate function? I can't find anything really helpful on it and although I realize it's pretty basic, I have no idea on how to actually do it Any help is greatly appreciated. Link to comment Share on other sites More sharing options...
samme Posted May 4, 2018 Share Posted May 4, 2018 One is just to copy and modify the original function body, then overwrite the function: Phaser.Tween.prototype.start = function () { // ... }; Another is to save the original and call it from the new function: var tweenStart = Phaser.Tween.prototype.start; Phaser.Tween.prototype.start = function () { // special code ... tweenStart.call(this); // special code ... }; Zampano and Mickety 1 1 Link to comment Share on other sites More sharing options...
Zampano Posted May 4, 2018 Author Share Posted May 4, 2018 Okay, I didn't want to do the first in case there were any updates or fixes. The second one will do fine, thank you! Link to comment Share on other sites More sharing options...
Recommended Posts