【发布时间】:2011-12-20 08:10:43
【问题描述】:
我试图理解一些用 Javascript 编写的代码,但我被困在语法上。
var connections = {}; // I know '{}' means new Object()
var messages = {};
对象包含变量路径、版本等,但是在代码中以下几行是做什么的?
connections[ path ] = connections[ path ] || [];
messages[ path ] = messages[ path ] || { version: 0, body: ''};
【问题讨论】:
-
悬而未决,
{}与new Object()不同(即使Object未被覆盖)。但它已经足够接近了。差异是微妙的,您可能永远不会注意到差异。 -
@tri:如果您实际上并没有说出区别是什么,我不确定指出一个小的迂腐细节错误是否有帮助。
-
@trinithis——说吧。 ES5 11.1.5 说:
The production ObjectLiteral : { } is evaluated as follows: 1. Return a new object created as if by the expression new Object() where Object is the standard built-in constructor with that name。那么“细微差别”是什么? -
对不起,我真的很累。由于某种原因,我认为有细微的差别,但我不记得了。
标签: javascript arrays literals notation