Last active
August 29, 2015 13:56
-
-
Save vitkon/9299050 to your computer and use it in GitHub Desktop.
Simple JS Prototype chain
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 (name) { | |
this.name = name; | |
} | |
Person.prototype.test = function () { | |
return 'This is person test'; | |
} | |
Person.prototype.describe = function () { | |
return 'This is ' + this.name; | |
} | |
var Employee = function (name, title) { | |
Person.call(this, name); | |
this.title = title | |
} | |
Employee.prototype = Object.create(Person.prototype); | |
Employee.prototype.constructor = Employee; | |
Employee.prototype.describe = function () { | |
return Person.prototype.describe.call(this) + ' (' + this.title + ')'; | |
} | |
var vitaly = new Employee('Vitaly', 'Webdev'); | |
console.log(vitaly.describe()); | |
console.log(vitaly.test()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment