proposal-object-literal-coalescing-assignment

A proposal to introduce new assignment forms for ECMAScript object literals

MIT License

Stars
2

proposal-object-literal-coalescing-assignment

A proposal to introduce new assignment forms for ECMAScript object literals

const obj = {
  a: undefined,
  b?: undefined
}

Object.hasOwn(obj, 'a') // true
Object.hasOwn(obj, 'b') // false

Variations

Explicit string key

const obj = {
  'a' : undefined,
  'b' ?: undefined
  //  ^ 
  //   \___ Parsing the `?:` token    
}

Object.hasOwn(obj, 'a') // true
Object.hasOwn(obj, 'b') // false

Variable key alias

// Explicit string key
const a = undefined, b = undefined
const obj = {
  a,
  b?
// ^ 
//  \___ Parsing the `?` token    
}

Object.hasOwn(obj, 'a') // true
Object.hasOwn(obj, 'b') // false