Types and Name Instances

I am trying to clear the code of the game I am creating. From the very beginning, I turned on the corresponding functions inside the coverage object. For example, the initialization function can be accessed by Init.initialize().

However, for this and other objects, I would like to use types and then instantiate them. For example, I have a settings type that contains some game settings. The settings must be a type, while the instance must contain the actual settings.

Now what is the best way to name a type and how can I name an instance , especially when I have only one instance? If I name the type "Settings", what is the best way to describe an instance as a variable name?

+3
source share
2 answers

The best naming convention is one that can be read after six months without looking at the code.

In many cases, the Hungarian notation does not make sense if you do not remember what you had in mind.

For the settings object, call the prototype object

SettingsObject

and call instances

settings

because you (and anyone else reading the code) will understand what the SettingsObject instance will contain, and find out what the variable has settings. If you need a longer name, use a longer name, there is no penalty for being descriptive during development.

t. UnitMouseClickListeneror any other name that makes sense.

, . , .

+1

, . , :

// your class name
function Settings() {
  this.initialized = false;
}
Settings.prototype.initialize = function() {
  this.initialized = true;
}

var settings = new Settings();
settings.initialize();

. , . .

+2

Source: https://habr.com/ru/post/1786779/


All Articles