MV Inserting code into default's game functionality

JavaScript:
var _Scene_Map_onMapLoaded_base = Scene_Map.prototype.onMapLoaded;

Scene_Map.prototype.onMapLoaded = function () {

    _Scene_Map_onMapLoaded_base.call(this);
    //code
}

I have been using this on some plugins where i need to execute after the map is loaded (events created).
I guess i am inserting code between, or before the onMapLoaded..
don't really know..

I would love if someone could explain me exactly what is going on here.

Step by step, like if i was using the debugger (i tryed this), what am i doing here? is this like a middleware?
It means you're preserving the previous function in order to preserve the previous code. Then add your own.

Code:
var _Scene_Map_onMapLoaded_base = Scene_Map.prototype.onMapLoaded;
This is the code that preserves it.

Code:
_Scene_Map_onMapLoaded_base.call(this);
Then call the preserved code so that the original code is executed.

Code:
   //code
Then add your own.
Thank you very much. It makes sense now!

Original thread: https://forums.rpgmakerweb.com/threads/inserting-code-into-defaults-game-functionality.132422/