arun Posted September 14, 2017 Share Posted September 14, 2017 Hi friends, I am new in Phaser game development. I don't understand the following code below please help me var gameTitle = function(game){} gameTitle.prototype = { create: function(){ Link to comment Share on other sites More sharing options...
m4rk2s Posted September 14, 2017 Share Posted September 14, 2017 it's bizarre i've seen something like this one day that takes the game instance in parameter but the right syntax is game = new Phaser.Game(800, 600); and after in the function parameter you can add more stuff, then you go on the definition of the functions like preload, create and update Link to comment Share on other sites More sharing options...
mattstyles Posted September 15, 2017 Share Posted September 15, 2017 var gameTitle = function(game){} gameTitle.prototype = { create: function(){} } It's a JS pattern to add class-like behaviour into a prototypal language, if you know what classes are (in Java, C++ etc for example) then its pretty akin to that. The top function call is a constructor function, the prototype bit adds methods (behaviours) to your class. You should just call this an object as JS doesn't have traditional classes (despite the new class syntax). The way you're doing it though stamps over any existing methods on the prototype, this is generally bad, sometimes very bad. Extending the checkout with additional functionality is fine but be careful stamping over it, particularly if you're setting up some sort of inheritance chain. arun 1 Link to comment Share on other sites More sharing options...
Recommended Posts