Object prototype javascript example

JavaScript constructor function with name "Employee". Accepts a series of input parameters: "name, year of birth, gender".
A new object instance named "employee1" will be created from the constructor function.
From the prototype of the "Employee" constructor function we add the "city" method with the "prototype" keyword.

We also add the "showAll" method in which we show all the properties of "Employee".
First we try to show an undefined property "house", then we add this property only to the "employee1" object, so only this object will be the one that has this property defined, the rest of the instantiated objects will have to define it by means of the definition: " Employee.prototype.house = value".

Comments

PHP Captcha


Interesting Articles