Java Reference
In-Depth Information
Summary
In this chapter, we have demonstrated that JavaScript supports the three main concepts
of object-oriented programming: encapsulation, polymorphism, and inheritance. We have
looked at using constructor functions to create multiple instances of objects, as well as using
objects to create more objects. We have also seen how to use mixins to add modular func-
tionality to objects.
The key points of the chapter are summarized here:
• Object-oriented programming (OOP) is a way of programming that uses objects as
building blocks.
• The main concepts of OOP are encapsulation, polymorphism, and inheritance.
• Constructor functions can be used to create instances of objects.
• Inside a constructor function, the keyword this refers to the object returned by the
function.
• All instances of a constructor function inherit all the properties and methods of its
prototype object.
• The prototype object is live, so new properties and methods can be added to existing
instances.
• The prototype chain is used to find an available method. If an object lacks a method,
JavaScript will check whether its prototype has the method; if not, it will check that
function's prototype until it finds the method or reaches the Object constructor
function.
• Private properties and methods can be created by defining variables using var and
defining a function inside a constructor function. These can be made public using
getter and setter functions.
• Monkey-patching is the process of adding methods to built-in objects by augment-
ing their prototype objects. This should be done with caution as it can cause unex-
pected behavior in the way built-in objects work.
Search WWH ::




Custom Search