Skip to content

Instantly share code, notes, and snippets.

@vibhanshuc
Created February 15, 2016 07:37
Show Gist options
  • Save vibhanshuc/5c31cb0323f8a5a7ea77 to your computer and use it in GitHub Desktop.
Save vibhanshuc/5c31cb0323f8a5a7ea77 to your computer and use it in GitHub Desktop.
(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(',\n');
};
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, {
getGrade: {
value: function () {
return 'Grade: ' + this.grade.toString();
}
},
getSchool: {
value: function () {
return 'School: ' + this.school.toString();
}
},
getSummary: {
value: function () {// override
var tempSummary = Person.prototype.getSummary.apply(this);
return [tempSummary, this.getGrade(), this.getSchool()].join(',\n');
}
}
});
var person = new Person('Sachin Tendulkar',
42,
'Male'),
student = new Student('Arjun Tendular',
16,
'Male',
12,
'Shardahram School');
person.getSummary();
//Name: Sachin Tendulkar,
//Gender: Male,
//Age: 42
console.log(student.getSummary());
// Name: Arjun Tendular,
// Gender: Male,
// Age: 16, Grade: 12, School: Shardahram School
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment