Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Vibhanshu Chaturvedi on 13/2/16.
- */
- (function () {
- 'use strict';
- function Person(name, age , gender) {
- this.name = name;
- this.age = age;
- this.gender = gender;
- }
- Person.prototype.getName = function() {
- return 'Name: ' + this.name.toString();
- };
- Person.prototype.getAge = function() {
- return 'Age: ' + this.age.toString();
- };
- Person.prototype.getGender = function() {
- return 'Gender: ' + this.gender.toString();
- };
- Person.prototype.getSummary = function () {
- return [this.getName(), this.getGender(), this.getAge()].join(', ');
- };
- function Student(name, age, sex, grade, school) {
- Person.call(this, name, age, sex);
- this.grade = grade;
- this.school = school;
- }
- Student.prototype = Object.create(Person.prototype);
- Student.prototype.getGrade = function () {
- return 'Grade: ' + this.grade.toString();
- };
- Student.prototype.getSchool = function () {
- return 'School: ' + this.school.toString();
- };
- Student.prototype.getSummary = function () {
- return [this.getName(), this.getGender(), this.getAge(), this.getGrade(), this.getSchool()].join(', ');
- };
- var person = new Person('Sachin Tendulkar', 42, 'Male');
- person.getSummary(); //Name: Sachin Tendulkar, Gender: Male, Age: 42
- var student = new Student('Arjun Tendular', 16, 'Male', 12, 'Shardahram School');
- student.getSummary(); // Name: Arjun Tendular, Gender: Male, Age: 16, Grade: 12, School: Shardahram School
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement