Вопрос

I was looking at gruntjs and I looked at some JSON examples used to configure Grunt tasks.

Here is an example of the JSON:

grunt.initConfig({
  concat: {
    foo: {
      // concat task "foo" target options and files go here.
    },
    bar: {
      // concat task "bar" target options and files go here.
    },
  },
  uglify: {
    bar: {
      // uglify task "bar" target options and files go here.
    },
  },
});

As you can see, there is an 'extra' comma after each of the bar properties. I tried this notation in Chrome and it is valid. Although it is valid, I wouldn't use this notation but why would people use it?

Это было полезно?

Решение

I tried this notation in Chrome and it is valid.

Simply because it works in Chrome doesn't mean it's valid. It is valid because the spec says so :-)

I wouldn't use this notation but why would people use it?

To make copy&pasting easier. You can just append new properties without caring additional work. It's a bad practice in program code because older browsers (notably IE) and the ES3 spec disallow them, but in a config file (i.e. in a known environment) it makes life easier.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top