new Class(data)
Provides a nicer syntax for defining classes, with support for OO-style inheritance.
As JavaScript is not a real object-oriented language,
"class definitions" have to be written by manually
adding each member function to the
Note: Currently, the API3.Class is not compatible with the JsDoc documentation generator, so to document any class it has to be rewritten into the normal style.
prototype member which causes cumbersome
code. This utility function allows for a more readable
class definition.Note: Currently, the API3.Class is not compatible with the JsDoc documentation generator, so to document any class it has to be rewritten into the normal style.
Parameters:
data
|
The definition of the class, usually inline. |
- Source:
- class.js, line 46
Example
// Former definition of the API3.Entity class
API3.Entity = API3.Class({
// Parent class
_super: API3.Template,
// Constructor
_init: function(sharedAI, entity) {
// Call inherited constructor, important to keep this:
this._super.call(this, sharedAI.GetTemplate(entity.template));
// Regular constructor operation:
this._templateName = entity.template;
...
},
// Member functions
toString: function() {
return "[Entity " + this.id() + " " + this.templateName() + "]";
},
id: function() {
return this._entity.id;
},
...
});