Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save lamprosg/ba27169a0255122ff870 to your computer and use it in GitHub Desktop.

Select an option

Save lamprosg/ba27169a0255122ff870 to your computer and use it in GitHub Desktop.
(Javascript) - Creating objects with inheritance
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();
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