I'm following this melon JS tutorial, and am on part 3.
I am not clear on a couple things in this code snippet
game.PlayerEntity = me.ObjectEntity.extend({
init: function(x, y, settings) {
this.parent(x, y, settings);
... more code here
},
Firstly, you're creating a new member in my "game" object called "PlayerEntity" which extends the melonJS (me) Object Entity class. I get that. But I don't understand
1) is the this
referring to "game" object?
2) If so, then this.parent
would be referring to the parent of "game"- is this just the ObjectEntity class that it's inheriting from?
3) Why can't I call this from outside game
object as such? It's saying it has no method init
even though I've defined one in game.PlayerEntity {}
object.
game.PlayerEntity.init(1, 2, 3);
4) if you're calling the constructor with this.parent(x, y, settings)
, where are x, y, settings
parameters being set? With Java, you call a constructor as such:
public Bicycle(int val1, int val2) {
myVal1 = val1;
myVal2 = val2;
}
then create new instance of class:
Bicycle bike = new Bicycle(1, 2);
Therefore the constructor of Bicycle is being called when you create the instance.
But with this, It's not clear to me how this.parent(x, y, settings);
is "calling the constructor".
Thanks!