Prototype Objects
Explore the concept of prototype objects in JavaScript and understand how constructor functions use prototypes. Learn to access, visualize, and leverage prototype properties to share methods and enhance objects efficiently.
In this lesson, we will learn about the major concept of “Prototype Objects” in JavaScript.
Before we get into how it can be used, let’s discuss what a prototype is.
Prototype Properties in Objects
Instead of jumping directly into the definition, let’s begin by looking at the code below:
As seen above, if we display employeeObj, the three properties, name, age and designation are displayed along with their values, encapsulated within the EmployeeConstructor object, which was created using new.
If the same code is run locally on the browser, the browser console will display the following:
Notice anything different? Apart from age, designation and ...