-
Notifications
You must be signed in to change notification settings - Fork 3
Configuration
ClassicalJS allows you to customize and configure many of its parts.
##Changing the configuration options
You can change the configuration options for the whole library or for an individual class.
###Configuration of the whole library
To change the configurations for the whole library you use Class.Config
.
Example:
Class.Config({
constructorName: "__construct"
});
The configuration options you pass to Class.Config
will be merged with the default configuration of the library.
These configurations will now be applied to all the newly defined Classes.
###Configuration of an individual Class
To change the configurations for an individual Class you have two options:
1.You can either pass the configurations as the second argument of Class
.
Example:
var Person =
Class("Person", { globalize: false})
...
...
...
.End()
2.Or use the .Config
method.
Example:
var Person =
Class("Person")
Config({
superName: "parent"
})
...
...
End()
The configurations of an individual Class will inherit from the library's configurations and any changes you make to it will only be applied for the Class you're currently are defining.
##The configuration options
All of the below configuration options can be set to either the whole library, using Class.Config
, or for a single Class, using the .Config
method of the Class.
###>constructorName
(Default: "_constructor")
constructorName
defines the name that the constructor of a Class is given.
Example:
Class.Config({ constructorName: "__construct" }); //let's change the constructorName to __construct
/*in Person.js*/
var Person =
Class("Person")
Private("profession")
Constructor(function(profession){
this.profession = profession
})
...
End()
/*in Programmer.js*/
var Programmer =
Class("Programmer").Extends("Person")
Constructor(function(){
//We want to call the super-class constructor:
this.Super.__construct("Web Developer"); //we use __construct since it's what we set as the constructorName
})
...
End()
###>superName
(Default: "Super")
Just like constructorName
allows you to modify the name that is given to a Class's constructor, superName
allows you to change the name that is given to a Class's Super.
Example:
Class.Config({ superName: "_parent" }); //let's change the superName to _parent
/*in Person.js*/
var Person =
Class("Person")
Private("profession")
Constructor(function(profession){
this.profession = profession
})
...
End()
/*in Programmer.js*/
var Programmer =
Class("Programmer").Extends("Person")
Constructor(function(){
//We want to call a method of the super-class:
this._parent._constructor("Web Developer"); //we use _parent since it's what we set as the superName
})
...
End()
###>globalize
(Default: true)
globalize
indicates whether .Public
/.Private
/etc. should be added to the global scope while a Class is being defined. Setting it to false makes the no-dots notation disabled (TODO: link to no-dots notation page).
Example:
/*in Person.js*/
var Person =
Class("Person", { globalize: false }) //we're disabling the no-dots notation for this Class
.Private("profession")
.Constructor(function(profession){
this.profession = profession
})
...
.End()
###>keepDefinedClasses
(Default: true)
keepDefinedClasses
indicates whether ClassicalJS should keep a reference of the Classes you define.
This allows you to just have to pass a string to .Extends
.
Example:
/*in Person.js*/
var Person =
Class("Person")
...
...
...
End()
/*in Programmer.js*/
var Programmer =
Class("Programmer").Extends("Person")
...
...
...
End()
if keepDefinedClasses
was set to false, you would have to do this:
Class.Config({ keepDefinedClasses: false })
/*in Person.js*/
var Person =
Class("Person")
...
...
...
End()
/*in Programmer.js*/
var Programmer =
Class("Programmer").Extends(Person) //we are passing the object itself here, not a string
...
...
...
End()
Setting keepDefinedClasses
to false makes the name
passed to Class
a bit useless, though it can still help in debugging.