tc39 / proposal-extended-numeric-literals

Extensible numeric literals for JavaScript
https://tc39.github.io/proposal-extended-numeric-literals/
72 stars 18 forks source link

Clash with existing `with` statement #31

Open C-Ezra-M opened 1 year ago

C-Ezra-M commented 1 year ago

There's already a with statement, taken directly from C++, which has static typing. It's not commonly used in JavaScript, mostly because of dynamic typing and the fact it's disabled in strict mode.

let a, c, r;
r = 5;
with (Math) {
  c = r *  2 * PI;
  a = r ** 2 * PI;
}

An alternative to such a statement is creating a block not triggered by control flow and destructure the things you need:

let a, c, r;
r = 5;
{
  const { PI } = Math;
  c = r *  2 * PI;
  a = r ** 2 * PI;
}

I think the with from this proposal should eventually supersede the existing with.