Skip to content

Optional curlies around objects as method parameters #30

Closed
@jnicklas

Description

@jnicklas

I really like Ruby's way of making the curlies optional when passing a hash as the last argument to a function:

 monkey "blah", { :foo => 2, :bar => 3 }  # with curlies
 monkey "blah", :foo => 2, :bar => 3      # without curlies

It makes it look like named arguments. Is it possible to do the same in CoffeeScript?

monkey("blah", { foo: 2, bar:3 })        # with curlies
monkey("blah", foo: 2, bar:3)            # without curlies

Currently, this compiles to:

monkey("blah", {
  foo: 2,
  bar: 3
});
// with curlies
monkey("blah", foo = 2, bar = 3);
// without curlies

So the second example is valid Coffee, and compiles into an assignment. My suggestion is to make the second one compile to the same code as the first one.

Seems to me like this would be pretty hard on the parser and potentially introduce some confusion, so I'm not sure this is worth it at all, what do you think?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions