June 2016
Beginner to intermediate
292 pages
6h 8m
English
A simple way to fix the inconsistencies of the convention-based approach is not using properties for internal members but declaring variables inside the constructor, as shown in the following example:
function TheatreSeats() {
var seats = [];
this.placePerson = function(person) {
seats.push(person);
};
}
Using this approach, we can continue to use the constructor as usual preventing the access to the actual internal container-the seats variable. We are exploiting the internal environment of the TheatreSeats() function to hide the implementation details and lay the foundations for building the private and public parts of JavaScript objects.
Before going further, it is useful to make clear some concepts ...
Read now
Unlock full access