-
Notifications
You must be signed in to change notification settings - Fork 3
No Dots Notation
The no-dots notation consists of not writing any dots before Public
, Private
, etc.
Example:
var Person =
Class("Person")
Private ("firstName");
Private ("LastName");
Public (function setFirstName(firstName){
this.firstName = firstName;
});
Public (function setLastName(lastName){
this.lastName = lastName;
});
Public(function getFullName(){
return this.firstName + " " + this.lastName;
});
End()
This works because when you invoke Class
, methods like Public
, Private
, etc. get "exported" to the global scope for you to use.
When you invoke End
, all these added globals get removed.
The functions that get added to the global scope are: Private
, Protected
, Public
, Extends
, End
, Constructor
, Config
, _
, PersistentPlugins
.
Don't worry: if you have something like underscore.js on your page, yes the global variable "_" will be overwritten when you call Class
, but it's old value will be restored when you call End
.
If you wish to disable the no-dots notation, then set globalize
to false
in the configuration options.
Without the no-dots notation, you'll have to write your Classes using chainability; like this:
var Person =
Class("Person")
.Private ("firstName")
.Private ("LastName")
.Public (function setFirstName(firstName){
this.firstName = firstName;
})
.Public (function setLastName(lastName){
this.lastName = lastName;
}). //you can also put the dots at the end
Public(function getFullName(){
return this.firstName + " " + this.lastName;
}).
End()
You just have to remember to never put a ;
and always put a .