The with
statement is not available at all in strict mode, because it leads to ambiguity and has other problems. However, would it be possible and sensible to reintroduce a subset of its functionality, e.g. limiting the parenthetical expression to predefined objects like Math
?
var a, x, y;
var r = 10;
with (Math) {
a = PI * r * r;
x = r * cos(PI);
y = r * sin(PI / 2);
}
(Example courtesy of MDN.)
var a, x, y;
var r = 10;
const Ο = Math.PI;
a = Ο * r * r;
x = r * Math.cos(Ο);
y = r * Math.sin(Ο / 2);
var a, x, y;
var r = 10;
a = Math.PI * r * r;
x = r * Math.cos(Math.PI);
y = r * Math.sin(Math.PI / 2);