Skip to content

Instantly share code, notes, and snippets.

@jyotiarora2610
Created July 14, 2018 16:53
Show Gist options
  • Save jyotiarora2610/02ae1b5741caaed303f1bb1c78c1437b to your computer and use it in GitHub Desktop.
Save jyotiarora2610/02ae1b5741caaed303f1bb1c78c1437b to your computer and use it in GitHub Desktop.
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