Skip to content

Instantly share code, notes, and snippets.

@vitkon
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitkon/9299050 to your computer and use it in GitHub Desktop.
Save vitkon/9299050 to your computer and use it in GitHub Desktop.
Simple JS Prototype chain
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