以下将显示在 Firebug 或jsconsole.com或其他 Javascript 交互式控制台中:
>>> foo = { a : 1, b : 2.2 }
Object { a=1, more...}
>>> foo.a
1
>>> foo.b
2.2
>>> { a : 1, b : 2.2 }
SyntaxError: invalid label { message="invalid label", more...}
>>> { a : 1 }
1
为什么1
返回{a : 1}
,为什么{a : 1, b : 2.2}
给出错误?在 Ruby 中,它们会以您定义它的方式返回。