w = {c: true}
w =
a: 4
b: true
console.log w
I expect the result w to be {a: 4, b: true, c: true}, but I get {a: 4, b: true}.
How can I do multiple assignments to object properties without loosing already set properties?
w = {c: true}
w =
a: 4
b: true
console.log w
I expect the result w to be {a: 4, b: true, c: true}, but I get {a: 4, b: true}.
How can I do multiple assignments to object properties without loosing already set properties?
CoffeeScript: assigning multiple properties to an initialised object has been the best answer so far.
But if you only want to add a few properties to an object you can just do:
w = {c: true}
w.a = 4
w['b'] = true # alternative notation
Also, this question is more about JavaScript than CoffeeScript.
I don't think it can be done directly. I believe, you need to iterate:
w = {c: true}
temp =
a: 4
b: true
w[k] = v for k,v of temp
console.log w