Through this simple JavaScript tutorial, you would learn about Public and Private methods in the JavaScript OOP.
- Demo
- Enlarge
- Reload
- New window
Free iPage Web Hosting for First Year NOW
If you're still looking for a reliable web host provider with affordable rates, why you don't take a little of time to try iPage, only with $1.89/month, included $500+ Free Extra Credits for the payment of 24 months ($45)?
Over 1,000,000+ existisng customers can not be wrong, definitely you're not, too! More important, when you register the web hosting at iPage through our link, we're going to be happy for resending a full refund to you. That's awesome! You should try iPage web hosting for FREE now! And contact us for anything you need to know about iPage.
/**
* A scrollable list that can display large numbers of contacts.
*
* @param contacts contact objects
*/
xp.ContactSelector = function(args) {
/** Container for public functions. */
var self = {};
/** Container for private functions. */
var _ = {};
/**
* Initializes the object.
*/
_.initialize = function() {
if (!args.contacts) {
_.installSearchbox();
}
};
/**
* Adds a searchbox to the ContactSelector.
*/
_.installSearchbox = function() {
// This is a private method
};
/**
* Returns the contacts that the user has selected
*
* @return the selected contact objects
*/
self.getSelectedContacts = function() {
// This is a public method
};
. . . . . . . . . .
_.initialize();
return self;
};
Private methods begin with
_.
, while public methods begin with self.
. There are some interesting things about this setup:- Public methods are accessible on the object created by this function. Private methods are not accessible.
- Public and private methods can be defined in any order, regardless of which calls which. This is because they are properties of self and _. If they were defined as standalone functions, then order would matter.
- You can inherit from another object by adding the following to initialize():
self = xp.AbstractContactSelector(args);
- Sent (0)
- New