0

Recently while working with javascript object in my chrome console I got confused with the log information about my object,Please help be understand it.

function makeFunction()
{
  this.name="Some Name";
  this.display=function(){return this.name;};
  this.returning=function(){return this.display;};
}
    
var object1=new makeFunction();


console.log(object1);//First console log of object1


object1.name="Another name";//trying to change the property of object1

console.log(object1);//Second console log of object1

I updated the name property of object1 but when the result was printed it seemed like this

The references to the name in display function in first console log is changed but the original reference seemed to be "Some Name" only can anyone explain why?

Keith
  • 22,005
  • 2
  • 27
  • 44
  • 1
    The code appears to work fine in the snippet. The Chrome console is notorious for being asynchronous and misleading in cases like this. – Pointy Mar 19 '18 at 14:34
  • Chrome's console log will keep a reference, so when you expand it for more details it will evaluate the current state, this is normal.. – Keith Mar 19 '18 at 14:38

0 Answers0