Last active
August 29, 2015 14:21
-
-
Save lamprosg/ba27169a0255122ff870 to your computer and use it in GitHub Desktop.
(Javascript) - Creating objects with inheritance
This file contains hidden or 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 Employee() { | |
| this.name = ""; | |
| this.dept = "general"; | |
| } | |
| function WorkerBee() { | |
| Employee.call(this); | |
| this.projects = []; | |
| this.getInfo = function() { | |
| return "WorkBee class"; | |
| }; | |
| } | |
| WorkerBee.prototype = Object.create(Employee.prototype); | |
| function SalesPerson() { | |
| WorkerBee.call(this); | |
| this.dept = "sales"; | |
| this.quota = 100; | |
| } | |
| SalesPerson.prototype = Object.create(WorkerBee.prototype); | |
| --------- | |
| var mark = new WorkerBee() | |
| mark.name = ""; | |
| mark.dept = "general"; | |
| mark.projects = []; | |
| //Call member function | |
| mark.getInfo(); |
This file contains hidden or 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
| public class Employee { | |
| public String name = ""; | |
| public String dept = "general"; | |
| } | |
| public class WorkerBee extends Employee { | |
| public String[] projects = new String[0]; | |
| } | |
| public class SalesPerson extends WorkerBee { | |
| public double quota; | |
| public dept = "sales"; | |
| public quota = 100.0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment