Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. /**
  2. * Created by Vibhanshu Chaturvedi on 13/2/16.
  3. */
  4.  
  5. (function () {
  6. 'use strict';
  7.  
  8. function Person(name, age , gender) {
  9. this.name = name;
  10. this.age = age;
  11. this.gender = gender;
  12. }
  13.  
  14. Person.prototype.getName = function() {
  15. return 'Name: ' + this.name.toString();
  16. };
  17.  
  18. Person.prototype.getAge = function() {
  19. return 'Age: ' + this.age.toString();
  20. };
  21.  
  22. Person.prototype.getGender = function() {
  23. return 'Gender: ' + this.gender.toString();
  24. };
  25.  
  26. Person.prototype.getSummary = function () {
  27. return [this.getName(), this.getGender(), this.getAge()].join(', ');
  28. };
  29.  
  30. function Student(name, age, sex, grade, school) {
  31. Person.call(this, name, age, sex);
  32. this.grade = grade;
  33. this.school = school;
  34. }
  35.  
  36. Student.prototype = Object.create(Person.prototype);
  37.  
  38. Student.prototype.getGrade = function () {
  39. return 'Grade: ' + this.grade.toString();
  40. };
  41.  
  42. Student.prototype.getSchool = function () {
  43. return 'School: ' + this.school.toString();
  44. };
  45.  
  46. Student.prototype.getSummary = function () {
  47. return [this.getName(), this.getGender(), this.getAge(), this.getGrade(), this.getSchool()].join(', ');
  48. };
  49.  
  50. var person = new Person('Sachin Tendulkar', 42, 'Male');
  51.  
  52. person.getSummary(); //Name: Sachin Tendulkar, Gender: Male, Age: 42
  53.  
  54. var student = new Student('Arjun Tendular', 16, 'Male', 12, 'Shardahram School');
  55.  
  56. student.getSummary(); // Name: Arjun Tendular, Gender: Male, Age: 16, Grade: 12, School: Shardahram School
  57.  
  58.  
  59. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement