JavaScript runs only last function -


i have following testing code: edit:

 var getit = function () {       return this.x;       };  var obj1 = {   : getit,   x : 11 };  var obj2 = {   : getit,   x : 12 };  obj1.get(); obj2.get(); obj1.get(); 

when run code, last function returns value of 11. instead of seeing 3 values, see last one. if delete last line, see 12 why that?

i believe running code in console or wouldn't seeing value @ all. default behavior of consoles display result of latest expression.

if want values logged, can explicitly log individual expressions using console.log.

console.log(obj1.get()); console.log(obj2.get()); obj1.get(); 

note code doesn't run, assumed did since haven't mentioned errors.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -