js with All In One



js with All In One

不推荐,要废弃 ????

js with All In One_with


function f(x, o) {
with (o) {
console.log(x);
}
}
function f(foo, values) {
with (foo) {
console.log(values);
}
}


var a, x, y;
var r = 10;

with (Math) {
a = PI * r * r;
x = r * cos(PI);
y = r * sin(PI / 2);
}


refs

​https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with​

​https://2ality.com/2011/06/with-statement.html​

​https://stackoverflow.com/questions/1931186/with-keyword-in-javascript​

​https://stackoverflow.com/questions/61552/are-there-legitimate-uses-for-javascripts-with-statement​