why should i use prototypes is js?
for example if i want to create a constructor like:
var Person = function(name, yearOfBirth){
this.name = name;
this.yearOfBirth = yearOfBirth;
this.calculateAge = function(){
console.log(2018-this.yearOfBirth);
}
}
is better to use prototype for functions like:
var Person = function(name, yearOfBirth){
this.name = name;
this.yearOfBirth = yearOfBirth;
}
Person.prototype.calculateAge = function(){
console.log(2018-this.yearOfBirth);
}
should i use prototype also for props like name etc?
Can someone tell me the differences between using or not prototypes and what's the best use of it?
Thanks
EDIT: this is the best answer that i've found: https://hackernoon.com/prototypes-in-javascript-5bba2990e04b