![]() The reason this is necessary, is because Scene_Boot_start doesn't belong to the Scene_Boot object, even though the function we saved to it does. In other words, we're forcing the context of Scene_Boot_start to be the same as our current context (the context of Scene_Boot.start). ![]() In this case, our context object also happens to be our current this object. ![]() This is why we use the call(context) function, which ensures that the function (in this case the Scene_Boot.start function) will use the context object as its this object. Unfortunately, JavaScript can be very confusing when it comes to context. (Note: it is currently 1AM over here, and I'm not entirely 100% sure what I'm saying is correct)Īnd finally, the main part of our new function: I honestly don't know a single other programming language that does this. If you think this is confusing, that's because it is confusing. Instead, it belongs to the Window object, also known as the "global scope". While Player.die describes the behavior of the die() function for a Player, you don't want player1.die() to also affect player2, so the this object in player1.die() refers to player1, and in player2.die() it would refer to player2 instead. For example, if you have a class Player, then you can use it to create 2 Player objects, such as player1 and player2. The this keyword can represent a different object, depending on which object the currently running function belongs to. When a function belonging to Scene_Boot is trying to use another function belonging to Scene_Boot, it needs to access it using the this keyword, which represents the current Scene_Boot object, since there could be more than one (although in this case there aren't). It contains all variables and functions that a Scene_Boot object would need. The call(this) part is a bit more complicated to explain, and is easier to understand once you know about object oriented programming.īasically, Scene_Boot is a "class", a template for objects (though in this case, we only need 1 Scene_Boot object). Scene_Boot_start.call(this) Is what calls the original Scene_Boot_start function, so our new function can reproduce the original function's behavior.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |