Created
July 8, 2013 03:27
-
-
Save zhongzhu/5946033 to your computer and use it in GitHub Desktop.
how to use js to do inheritance of OOD
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 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