Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. Employee.prototype= new Person();
  2. Employee.prototype.constructor=Employee;
  3.  
  4. <script type="text/javascript">
  5. function Person(age, weight) {
  6. this.age=age;
  7. this.weight=weight;
  8. this.getInfo=function() {
  9. return "I am " + this.age + " years old " +
  10. "and weighs " + this.weight +" kilo.";
  11. }
  12. }
  13. function Employee(age, weight, salary){
  14. this.salary=salary;
  15. this.age=age;
  16. this.weight=weight;
  17. this.getInfo=function() {
  18. return "I am " + this.age + " years old " +
  19. "and weighs " + this.weight +" kilo " +
  20. "and earns " + this.salary + " dollar.";
  21. }
  22. }
  23. Employee.prototype= new Person();
  24. Employee.prototype.constructor=Employee;
  25. // The argument, 'obj', can be of any kind
  26. // which method, getInfo(), to be executed depend on the object
  27. // that 'obj' refer to.
  28. function showInfo(obj) {
  29. document.write(obj.getInfo()+"<br>");
  30. }
  31. var person = new Person(50,90);
  32. var employee = new Employee(43,80,50000);
  33. showInfo(person);
  34. showInfo(employee);
  35. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement