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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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