closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Logical Assignment Operators [Feature Request]

Open rahbari opened this issue 4 years ago • 2 comments

Would you please add logical assignment operators as the proposal is in stage 4:

a ||= b; 
a &&= b;
a ??= b;

https://github.com/tc39/proposal-logical-assignment

rahbari avatar Jan 26 '21 13:01 rahbari

Thanks for the report, this does look like a very useful ES2021 feature.

(Full list is at https://github.com/tc39/proposals/blob/master/finished-proposals.md)

blickly avatar Jan 27 '21 01:01 blickly

yes, i currently use this syntax for singletons:

class Singleton {
  static instance() {
    return this.instance ?? (this.instance = new this());
  }
}

which can be replaced by:

return this.instance ??= new this();

rahbari avatar Jan 27 '21 04:01 rahbari