{+flag}, {-flag} as shorthand for {flag: true}, {flag: false} · Issue #885 · jashkenas/coffeescript (original) (raw)

It's great that {foo} is shorthand for {foo: foo}, because that's a common (and awkward) construction; {option: true} and {option: false} are also very common, and a series of options could be made much more readable by introducing a shorthand. For instance, instead of

options = {invert: true, buffer: false, copy: true, thumbnail: false, zoom: true}

you could write

options = {+invert, -buffer, +copy, -thumbnail, +zoom}

I see this as a significant improvement in readability—it's much easier to check whether a particular option is enabled or disabled— as well as sheer succinctness.

Note that I'm proposing that this syntax only work inside of explicit curly braces, just as the {foo: foo} shorthand should only work that way (currently, no one has figured out how to implement this desired behavior).