Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logical Assignment Operators [Feature Request] #3760

Open
rahbari opened this issue Jan 26, 2021 · 2 comments
Open

Logical Assignment Operators [Feature Request] #3760

rahbari opened this issue Jan 26, 2021 · 2 comments

Comments

@rahbari
Copy link

rahbari commented Jan 26, 2021

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

@blickly
Copy link
Contributor

blickly commented Jan 27, 2021

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)

@rahbari
Copy link
Author

rahbari commented Jan 27, 2021

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants