最佳答案
我现在正在读特雷弗 · 伯纳姆的 异步 Javascript,这是一本很棒的书。
他谈到这个代码片段和 console. log 在 Safari 和 Chrome 控制台中是“异步的”。不幸的是,我无法复制这个。密码如下:
var obj = {};
console.log(obj);
obj.foo = 'bar';
// my outcome: Object{}; 'bar';
// The book outcome: {foo:bar};
If this was async, I would anticipate the outcome to be the books outcome. console.log() is put in the event queue until all code is executed, then it is ran and it would have the bar property.
虽然它是同步运行的。
我运行这段代码是错误的吗? console. log 实际上是异步的吗?