interstar
interstar

Reputation: 27206

Setting up nested dictionaries in CoffeeScript

I'm finding the CoffeeScript compiler baulks at this :

a = {'a':1,
     'b': { 'b1':1, 'b2':2 }
     }

Is that right? CoffeeScript can't create nested dictionaries?

Upvotes: 0

Views: 1201

Answers (2)

Douglas
Douglas

Reputation: 37761

CoffeeScript is whitespace sensitive, even when using braces. Either don't use the braces as suggested by limelights, or ensure that the whitespace matches when using braces:

a = {
  'a': 1,
  'b': { 'b1': 1, 'b2': 2 }
}

Upvotes: 1

Henrik Andersson
Henrik Andersson

Reputation: 47202

Nested JavaScript objects or "dicts" is no match for the CS compiler.

a =
   a: 1
   b:
     b1: 1
     b2: 2

Produces this

a = {
  a: 1,
  b: {
    b1: 1,
    b2: 2
  }
};

Upvotes: 2

Related Questions