Proposal: GitHub - bertyhell/proposal-object-nullish-coalescing-operator: A proposal to introduce new shorthand assignment for ECMAScript object literals where the value is falsey/undefined/null
This proposal shows a new syntax for assigning properties to an object literal but only if the object is not falsy/null or undefined.
Short example:
const myPersonObj = {
firstName: person.name,
work?: person.occupation, // Only set work if person.occupation is truthy, by using the "?:" operator
street??: person.address // Only set street is person.address is not null and not undefined, by using the "??:" operator
};
I'm looking for feedback on:
- Finding a champion. Or if i can be the champion myself, how to do that?
- Should we add both operators? "?:" and "??:", or should we just add "?:" and have the behavior follow the modern nullish coalescing operator (only on null or undefined).
- What impact does this have on the interpreter process? (V8). Is this an easy change, or would detecting these operators cause the interpretation of object literals to significantly slow down?
- Feedback on shorthand notation. See the chapter "Other considerations"