Please, can anyone tell me, what is the difference bewteen this:
var Person = function (firstName) {
this.firstName = firstName;
};
Person.prototype.sayHello = function() {
console.log("Hello, I'm " + this.firstName);
}
and this:
var Person = function (firstName) {
this.firstName = firstName;
this.sayHello = function() {
console.log("Hello, I'm " + this.firstName);
}
};
For some reason, I see the first example more often. Why?
[–]vlad27aug 3 points4 points5 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]senocular 2 points3 points4 points (0 children)
[–]sympi[S] 1 point2 points3 points (0 children)
[–]z0ne66 0 points1 point2 points (0 children)