javascript - Why leave a trailing comma after a key value pair in an object literal? -
i looking @ gruntjs , looked @ json examples used configure grunt tasks.
here example of json:
grunt.initconfig({ concat: { foo: { // concat task "foo" target options , files go here. }, bar: { // concat task "bar" target options , files go here. }, }, uglify: { bar: { // uglify task "bar" target options , files go here. }, }, });
as can see, there 'extra' comma after each of bar properties. tried notation in chrome , valid. although valid, wouldn't use notation why people use it?
i tried notation in chrome , valid.
simply because works in chrome doesn't mean it's valid. valid because the spec says so :-)
i wouldn't use notation why people use it?
to make copy&pasting easier. can append new properties without caring additional work. it's bad practice in program code because older browsers (notably ie) , es3 spec disallow them, in config file (i.e. in known environment) makes life easier.
Comments
Post a Comment