I'm assuming that plugin code executes after all the base code does, and that you can thus override base functions.
As for this bit though... I read that this is a self-invoking function. Is this the entry point for plugins like main in C++?
(function() {})();
What exactly is this doing in the sticky template?
var parameters = PluginManager.parameters('template');
Not sure how C++ works, but a self invoking function is an entry point for plugins that need to be executed immediately and won't be executed repetitively.
And the parameters template is responsible for taking care of plugin parameters (you can see how it works in any yanfly plugins that have parameters you can set in the plugin manager).
Sorry I am late to the parade, but a note on C++ versus JavaScript.
C++ is a top-down execution (in most cases). While you can setup states with C++, it becomes a very different language.
JavaScript, in comparison, is a "state machine design" operation. As Kino mentioned - scopes are created and the code is executed "in scope".
An easy way to think about it is "event-based system", where you attach your JS code to an event.
Example: User clicked on "Items" menu item -> default function runs to display appropriate window.
You attach your code to the same event to display a message, or add/remove items.
Another example would be UI control: on UI ready and loaded -> create windows to display content.