Jump to content

function create() vs create: function()


Recommended Posts

No, they are not needed.

function create() {}

This is your standard create a function named create, this can also be rewritten like so:

var create = function() {}

They are for all intent and purposes the same.


The syntax of:

create: funtion() {}

has to be inside of an object.


What you are probably referring to is inside of a prototype object like so:

Game.State = function(game) {};Game.State.prototype = {  preload: function() {  },  create: function() {  },  update: function() {  }};

Which you can just rewrite as:

Game.State = function(game) {};Game.State.prototype.preload = function() {};Game.State.prototype.creat = function() {};Game.State.prototype.update = function() {};

This is the same as my second example. The two ways of writing it are usually interchangeable. The main difference is the first way (my second last example) will initialize the prototype to be whatever is inside the brackets so if the prototype had anything previously inside of it, it will be gone, which is easy to see as you are saying "prototype = {stuff}. Where the second way (my last example) will just add functions onto the prototype keeping any previously declared objects intact in the prototype.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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