As in the topic, when we are defining a future object (for ex.):
function Person(name) {
this.sayName = function() {
console.log(this.name);
};
}
Person.prototype.sayName = function() {
console.log(this.name);
};
both methods will be available for newly created object. The only difference is that the 'this' expression will create this method for every instance and with 'prototype' it will be shared in memory (as far as I know). I've faced both expressions and what is interesting the first one is far more popular than the second one.
My question is... what is the proper way in JavaScript the first or the second ? ( I know both works but... what is the code engineering standard and why ).