proposal-extended-numeric-literals icon indicating copy to clipboard operation
proposal-extended-numeric-literals copied to clipboard

Clash with existing `with` statement

Open C-Ezra-M opened this issue 2 years ago • 0 comments

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.

C-Ezra-M avatar Nov 23 '22 10:11 C-Ezra-M