javaScript:在数组中的最后一组值之后可以出现逗号吗? [英] javaScript: Can a comma occur after the last set of values in an array?

查看:29
本文介绍了javaScript:在数组中的最后一组值之后可以出现逗号吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在 javascript 中尾随数组的逗号是否有效?

I am wondering if a comma trailing an array in javascript is valid?

var settings = {
    'foo'  : oof,
    'bar' : rab,
};

对比

var settings = {
    'foo'  : oof,
    'bar' : rab
};

请注意,第二个示例的最后一个键/值后没有逗号.

Note the second example does not have a comma after the last key/value.

推荐答案

大多数浏览器和实现都允许尾随逗号,大的 BUT 是Internet Explorer".

Most browsers and implementations do allow a trailing comma, the big BUT is the "Internet Explorer".

大多数 InternetExplorer 版本中的尾随逗号会导致麻烦.它会抛出怪异疯狂、奇怪和不合理的错误 ..你不知道自己在哪里!这可怕,你会陷入深度和严重的抑郁.这种疾病还有一个名字,厄运的邪恶逗号",它曾被称为一次.

A trailing comma in most InternetExplorer versions causes BIG trouble. It'll throw wierd, crazy, strange and unreasonable errors .. you have no idea where you're at! This is terrible, you'll fall into deep and serious depressions. The disease also has a name, "evil comma of doom" it was called once.

结论:永远……永远!在 Javascript 中使用尾随逗号.

这篇关于javaScript:在数组中的最后一组值之后可以出现逗号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆