Last active
September 11, 2018 14:28
-
-
Save patrickporto/561d609f9790a1b6791e39030c817856 to your computer and use it in GitHub Desktop.
Classes (EcmaScript 5)
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
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