简体   繁体   English

关键字中的JavaScript对象冒号

[英]Javascript object colon in key

Enclosed a screenshot of the Javascript console (Chrome Version 36.0.1985.125 m) after executing: 执行后,随附了Javascript控制台(Chrome版本36.0.1985.125 m)的屏幕截图:

console.log(node)
console.log(node['read_cam0:x'])
console.log(node['label'])

在此处输入图片说明

Why is node["read_cam0:x"] undefined? 为什么未定义node["read_cam0:x"]

added issue at sigma.js: https://github.com/jacomyal/sigma.js/issues/361 在sigma.js中添加了问题: https : //github.com/jacomyal/sigma.js/issues/361

UPDATE: Firefox console shows this: 更新:Firefox控制台显示以下内容: 在此处输入图片说明

see the read_cam0 missing from the object on the left but displayed on the right (after clicking on object on the left side). 看到左侧对象缺少的read_cam0 ,但显示在右侧(单击左侧对象后)。

The expression obj["read_cam0:x"] works as you would expect and is not undefined . 表达式obj["read_cam0:x"]可以按您期望的方式工作,并且不是undefined

The return value of console.log() is always undefined (therefore the second line in your screenshot). console.log()的返回值始终是undefined (因此屏幕截图中的第二行)。 However, calling the function has the side-effect that it logs stuff to the console (the first line line in your screenshot). 但是,调用该函数的副作用是它将内容记录到控制台(屏幕快照的第一行)。

Entering console.log in the Chrome dev-console (as opposed to executing it in a javascript file) thus always results in two lines: 因此,在Chrome开发人员控制台中输入console.log (而不是在javascript文件中执行控制台)通常会导致两行:

Obviousely the chrome console shows the object in it's updated state while a line below it logs the state before the object was updated. 显然,chrome控制台显示对象处于更新状态,而其下方的一行记录了对象更新之前的状态。 The problem was identified by using a setTimeout . 通过使用setTimeout确定了问题。

This just means the object you are trying to print to the console is undefined. 这只是意味着您要打印到控制台的对象是未定义的。 The output would be [Object object] if it existed 如果存在,则输出为[Object object]

read_com0 is an object read_com0是一个对象

Try this: 尝试这个:

console.log(node)
console.log(node["read_cam0"]["x"])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM