jashkenas/coffee-script — Issue #2078: Existential Assignment Broken For Object Literals
Author: artlogic
Created: 2012-01-29 23:17:17+00:00
State: open

Given that assigning an object literal to a variable is done in the following way:

obj =
a: 1
b: 2

You would expect existential assignment to work similarly:

obj ?=
a: 1
b: 2

However, this is not the case, as `b` is left out of the object literal, as demonstrated by the following compiled javascript:

if (typeof obj === "undefined" || obj === null) {
obj = {
a: 1
};
}

({
b: 2
});

You can work around this issue by manually including commas - then everything works as expected:

obj ?=
a: 1,
b: 2