Created
February 15, 2016 07:37
-
-
Save vibhanshuc/5c31cb0323f8a5a7ea77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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