Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

jquery - javaScript: Can a comma occur after the last set of values in an array?

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

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

vs

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.

Conclusion: NEVER.. ever! use a trailing comma in Javascript.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...