I was trying to understand OOP model of JavaScript, so I was reading this article: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript
The following code was interesting:
function Person(gender) {
this.gender = gender;
alert('Person instantiated');
}
Person.prototype.gender = '';
var person1 = new Person('Male');
var person2 = new Person('Female');
//display the person1 gender
alert('person1 is a ' + person1.gender); // person1 is a Male
What was interesting and not clear to me is this line:
Person.prototype.gender = '';
I didn't understand so I tested the code both with that line and without it.
The code is working fine in both conditions.
So my question is:
Why did the author add that line?