1/* Answer to: "javascript prototype explained" */
2
3/*
4 The prototype object is special type of enumerable object to
5 which additional properties can be attached to it which will be
6 shared across all the instances of it's constructor function.
7
8 So, use prototype property of a function in the above example
9 in order to have age properties across all the objects as
10 shown below:
11*/
12
13function Student() {
14 this.name = 'John';
15 this.gender = 'M';
16}
17
18Student.prototype.age = 15;
19
20var studObj1 = new Student();
21alert(studObj1.age); // 15
22
23var studObj2 = new Student();
24alert(studObj2.age); // 15
1String.prototype.countCharacter = function(char) {
2 return [...this].filter(c => c === char).length;
3}