1 decade ago by aliken9
I was wondering if there is any preferred convention for working with Impact.
For example, examples I've seen most typically declares and instantiates all its variables as well as functions definitions within ig.Entity.extend({}) like so:
I've also seen code where variables and function are declared/defined before the ig.Entity.extend({}), for example:
The rationale for the latter style being that there are some functions that should be "private" to the entity and not modifiable by external code.
From my experience there does not seem to be an issue with using either of these styles, but I was wondering if there is a convention for doing either the first or the second method, and what is the rationale behind that?
For example, examples I've seen most typically declares and instantiates all its variables as well as functions definitions within ig.Entity.extend({}) like so:
.defines(function() { EntityButton = ig.Entity.extend({ font1: new ig.Font('...'), font2: new ig.Font('...'), x: 0, y: 0, init: function(x, y, settings) { ... }, process: function() { ... }, ...
I've also seen code where variables and function are declared/defined before the ig.Entity.extend({}), for example:
.defines(function(){ var spaceStr = "\nPress SPACE to continue!"; var str = "Hello there!"; function arrayShuffle(theArray) { ... } //initialize all questions function initQuizzes(){ ... }; EntityQuizBox = ig.Entity.extend({ quizText: new ig.Font('...'), size:{x:48, y:48}, init: function( x, y, settings ){ ... }, update: function(){ ... },
The rationale for the latter style being that there are some functions that should be "private" to the entity and not modifiable by external code.
From my experience there does not seem to be an issue with using either of these styles, but I was wondering if there is a convention for doing either the first or the second method, and what is the rationale behind that?