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.
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.An alternative to such a statement is creating a block not triggered by control flow and destructure the things you need:
I think the
with
from this proposal should eventually supersede the existingwith
.