Created
July 14, 2018 16:53
-
-
Save jyotiarora2610/02ae1b5741caaed303f1bb1c78c1437b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var person = function (firstName, age) { | |
this.name = firstName | |
this.age = age | |
} | |
person.prototype.getInfo = function () { | |
console.log(this.name + ' is ' + this.age + ' years old!') | |
} | |
var employee = function (firstName, age, salary) { | |
person.call(this, firstName, age) | |
this.salary = salary | |
} | |
employee.prototype = Object.create(person.prototype) | |
employee.prototype.constructor = employee | |
employee.prototype.getInfo = function () { | |
console.log(this.name + ' is ' + this.age + ' years old and the salary is ' + this.salary) | |
} | |
var p1 = new person('abc', 12) | |
var e1 = new employee('def', 24, 12000) | |
p1.getInfo() | |
e1.getInfo() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment