<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
// function
constructor
function Employee(name, job, yearOfBirth) {
this.name = name;
this.job = job;
this.yearOfBirth = yearOfBirth;
}
// adding
calculateAge() method to the Prototype property
Employee.prototype.calculateAge = function () {
console.log('The current age is: ' + (2019 - this.yearOfBirth));
}
console.log(Employee.prototype);
// creating
Object Person1
let Employee1 = new
Employee('Elon', 'Astronaut', 1986);
console.log(Person1)
let Employee2 = new
Employee('ET', 'Alien', 1997);
console.log(Person2)
Employee1.calculateAge();
Employee2.calculateAge();
</script>
</body>
</html>
No comments:
Post a Comment