Jump to content

gameState syntax


lastnightsparty
 Share

Recommended Posts

Hi guys,

 

When I create a new state.js file for my game I simply start with:

 

var gameState = {

    preload: function(){

etc...

 

but I've noticed that in most tutorials they use this syntax:

 

var gameState = function(game){};

gameState.prototype ={

    preload: function(){

etc...

 

Both work in my games. But what is the difference between them? (especially since the first is shorter)

 

Thanks for your help!

 

Link to comment
Share on other sites

I don't know the exact answer, it just works and I roll with it, If you are curious, read the SO question and the answers to get in more depth. Basically when you assign properties to object.prototype you are doing Object oriented programming in javascript. prototype is useful for inheritance, google for oop, inheritance, javascript for more resources, here's one from MDN. Also you can checkout some books about javascript to get in more depth about the language. Here's a book for advanced javascript: here, and here's a list of books.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...