fran Posted July 30, 2014 Share Posted July 30, 2014 Is there a difference between the two of them?I am reading this tutorial:http://toastedware.com/?p=258and I am wondering if the syntax:create:function (and other ones like update: function) are needed for "classes".Thanks. Link to comment Share on other sites More sharing options...
Dumtard Posted July 30, 2014 Share Posted July 30, 2014 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. Nebulocity, karyann, lewster32 and 2 others 5 Link to comment Share on other sites More sharing options...
fran Posted July 30, 2014 Author Share Posted July 30, 2014 Thank you very much Dumtard ! Very clear explanation. Link to comment Share on other sites More sharing options...
Recommended Posts