Skip to content

Instantly share code, notes, and snippets.

@zhongzhu
Created July 8, 2013 03:27
Show Gist options
  • Save zhongzhu/5946033 to your computer and use it in GitHub Desktop.
Save zhongzhu/5946033 to your computer and use it in GitHub Desktop.
how to use js to do inheritance of OOD
function Person(name)
{
this.name = name;
}
Person.prototype.toString = function() {
return "Person(name: " + this.name + ")";
}
function Employee(name, salary)
{
Person.call(this, name);
this.salary = salary;
}
Employee.prototype = new Person();
Employee.prototype.toString = function() {
return "Employee(name: " + this.name + " Salary: " + this.salary + ")";
}
var p1 = new Person("henry");
var p2 = new Person("helen");
print(p1);
print(p2);
var e = new Employee("Johnny", 50000);
print(e);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment