Created
July 11, 2015 01:07
-
-
Save JasonCust/54d08295d8e678f338fc to your computer and use it in GitHub Desktop.
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 = { | |
first: undefined, | |
last: undefined, | |
personMethod: function personMethod() { | |
console.log( this.first, this.last); | |
} | |
}; | |
var Employee = Object.create(Person); | |
Employee.position = undefined; | |
Employee.employeeMethod = function employeeMethod() { | |
console.log(this.position); | |
}; | |
var Manager = Object.create(Employee); | |
Manager.position = 'Manager'; | |
Manager.department = undefined; | |
Manager.managerMethod = function() { | |
console.log(this.department); | |
}; | |
// Using a new object | |
var manager = Object.create(Manager); | |
manager.first = 'Tom'; | |
manager.last = 'Jones'; | |
manager.department = 'Housewares'; | |
manager.employeeMethod(); // Manager | |
manager.personMethod(); // Tom Jones | |
manager.managerMethod(); // Housewares |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment