开发者

javascript object literal, value/no value?

I am using

console.log(p);
console.log(p.datestrshow);

However the output in the console is

javascript object literal, value/no value?

Why is it undefined when it is clearly not?


doing

for(i in p)
  console.log(i+': ', (typeof p[i] == 'function' ? 'function' : p[i]));
开发者_StackOverflow社区

results in

javascript object literal, value/no value?


The console.log doesn't make a clone of your p object when you call it.

What's happening is that p.datestrshow is indeed undefined when you console.log, but by the time you expand the p object in the console, it has been defined, and the console is showing the current state of the p object with datestrshow defined.

Here's a test you can do in the console:

var test = {a:'a'};
console.log( test );  // log to the console before we define 'b'
test.b = 'b';

Run this code in the console, then expand the object that was logged. Even though we clearly defined b after the console.log, it still shows up when you expand the object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜