Is there any difference between the below two functions?
function Person(name) {
Object.assign(this, {name});
}
Person.prototype.greet1 = () => {
console.log(`Hello, ${this.name}.`);
}
Person.prototype.greet2 = function() {
console.log(`Hello, ${this.name}.`);
}
console.log(Person.prototype);
//{ greet1: [Function (anonymous)], greet2: [Function (anonymous)] }
They both print ‘anonymous function’. My guess is they are the same except for the fact that the arrow function will not not have a scoped this within the function body — is that accurate, or what’s the difference in the above two greet functions?
