function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name
}
var tinu = new Person('Tinu');
console.log(tinu.getName()) //Prints the name 'Tinu' - Expected, means the function is added to protoype
console.log(tinu);
The last console.log() does not print the newly added method named 'getName' via dot prototype, prints only the property 'name', Here I would expect to print both property 'name' and also method 'getName' inside the Person object. Below is the actual output and desired output for the above code:
Actual output
Tinu
Person { name: 'Tinu' }
Desired output
Tinu
Person { name: 'Tinu', getName: [Function] }
The image below shows another example where the method 'getFullName' added via prototype is correctly shown while printing to console the object to which it is added. And was expecting the same with my example