Class
This is a function for creating classes.This is done by creating a generic constructor which inherits from a super class.
The returned constructor/class can be used just like any other constructor in JavaScript.
class creation
A class can be easyly created by calling:
Class(className="anonymous", superClass=Object, classScope)
parameters:
Class(className="anonymous", superClass=Object, classScope)
parameters:
- className The name of the new class.
- superClass The class to inherit from.
- classScope A function object which will be called with the class and super class as parameter upon class creation.
MyClass = Class("MyClass", function(thisClass, Super){
thisClass.prototype.init = function(){
//do initialization here
}
})
thisClass.prototype.init = function(){
//do initialization here
}
})
object initialization
When a class is instanciated the constructor will call the object'sinit(...) method. This method will not be called when a prototype of a class is created by the class's
createPrototype() method during inheritence.
All parameters passed to the constructor will be passed to the init method.
init basically acts as the constructor for the class.
To customize object initialization one only needs to specify an init method for the new object:
See above.
class methods
These are the methods each class object exposes.- createPrototype()
Returns a new prototye of the class for subclassing. Overwrite this method to customize inheritence/prototyping for your class. - toString()
Returns the string representation of the class. Overwrite this to customiz the string representation of your class.
class properties
These are the properties each class object exposes.- className
The class name for the class. This will be automatically set by Class. - superClass
The super class of the class. This will be automatically set by Class.
instance methods
These methods are exposed by objects created from the class.- init(...)
Initializes the created object.
Overwrite this method to customize initialization.
parameters:
All parameters passed to the constructor are also passed to the init method.
instance properties
- constructor
The class constructor(The class object).