Skip to content

Instantly share code, notes, and snippets.

@patrickporto
Last active September 11, 2018 14:28
Show Gist options
  • Save patrickporto/561d609f9790a1b6791e39030c817856 to your computer and use it in GitHub Desktop.
Save patrickporto/561d609f9790a1b6791e39030c817856 to your computer and use it in GitHub Desktop.
Classes (EcmaScript 5)
function Person(name) {
this.name = name;
}
Person.prototype.saysHello = function () {
return "Hello, my name is " + this.name;
};
function Employee(name, title) {
Person.call(this, name);
this.title = title;
}
Employee.prototype = new Person();
Employee.prototype.constructor = Employee;
Employee.prototype.describe = function () {
var parent = Person.prototype.saysHello.bind(this);
return parent() + " (" + this.title + ")";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment