Inheritance.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. Type.registerNamespace("Demo");
  2. Demo.Person = function(firstName, lastName, emailAddress) {
  3. this._firstName = firstName;
  4. this._lastName = lastName;
  5. this._emailAddress = emailAddress;
  6. }
  7. Demo.Person.prototype = {
  8. getFirstName: function() {
  9. return this._firstName;
  10. },
  11. getLastName: function() {
  12. return this._lastName;
  13. },
  14. getEmailAddress: function() {
  15. return this._emailAddress;
  16. },
  17. setEmailAddress: function(emailAddress) {
  18. this._emailAddress = emailAddress;
  19. },
  20. getName: function() {
  21. return this._firstName + ' ' + this._lastName;
  22. },
  23. dispose: function() {
  24. alert('bye ' + this.getName());
  25. },
  26. sendMail: function() {
  27. var emailAddress = this.getEmailAddress();
  28. if (emailAddress.indexOf('@') < 0) {
  29. emailAddress = emailAddress + '@example.com';
  30. }
  31. alert('Sending mail to ' + emailAddress + ' ...');
  32. },
  33. toString: function() {
  34. return this.getName() + ' (' + this.getEmailAddress() + ')';
  35. }
  36. }
  37. Demo.Person.registerClass('Demo.Person', null, Sys.IDisposable);
  38. Demo.Employee = function(firstName, lastName, emailAddress, team, title) {
  39. Demo.Employee.initializeBase(this, [firstName, lastName, emailAddress]);
  40. this._team = team;
  41. this._title = title;
  42. }
  43. Demo.Employee.prototype = {
  44. getTeam: function() {
  45. return this._team;
  46. },
  47. setTeam: function(team) {
  48. this._team = team;
  49. },
  50. getTitle: function() {
  51. return this._title;
  52. },
  53. setTitle: function(title) {
  54. this._title = title;
  55. },
  56. toString: function() {
  57. //return Demo.Employee.callBaseMethod(this, 'toString') + '\r\n' + this.getTitle() + '\r\n' + this.getTeam();
  58. return Demo.Employee.callBaseMethod(this, 'toString') + '\n' + this.getTitle() + '\n' + this.getTeam();
  59. }
  60. }
  61. Demo.Employee.registerClass('Demo.Employee', Demo.Person);