icn
icn

Reputation: 17876

coffee script - use parameter vairable in json data

I have a coffee script function

postData: (pattern) ->
  myData =
    a: "a string"
    pattern: 0
    f: false

It is evaluated as

{
  "a": "a string",
  "pattern": 0,
  "f": false
}    

It is not what I want. I would like pattern to be a string I passed in

Thanks for any help.

Upvotes: 0

Views: 39

Answers (1)

Larry Maccherone
Larry Maccherone

Reputation: 9523

postData: (pattern) ->
  myData =
    a: "a string"
    f: false
  myData[pattern] = 0
  return myData

See it working here.

Upvotes: 1

Related Questions