I'm new to JavaScript and Node.js and am learning OOP and came across two ways of calling a method.
My code:
var Person = function(name) {
this.fName = name;
};
Person.prototype.sayHello = function(){
console.log("Hello, I am " + this.fName);
}
var person1 = new Person("mike");
person1.sayHello();
var helloFunction = person1.sayHello;
helloFunction.call(person1);
Output:
Hello, I am mike
Hello, I am mike
Both uses produce the same results. Is there a situation where one version would be more proper than the other? Are there any advantages/disadvantages to the two calls?