From MDN:
Using
withis not recommended, and is forbidden in ECMAScript 5 strict mode. The recommended alternative is to assign the object whose properties you want to access to a temporary variable.
It seems like a great/useful/convenient feature. Why is it frowned upon? What other ways are there to achieve that effect? I don’t want to have to go:
veryLongNS.y = veryLongNS.myFunc(veryLongNS.x);
veryLongNS.z = 6;
veryLongNS.otherFunc();
veryLongNS.a = {
a:1,
b:2,
c:veryLongNS.processThree(3)
};
Here’s a related answer:
Are there legitimate uses for JavaScript's "with" statement?
Also: http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/
How about the following as an alternative?
Edit: For clarity and posterity, this is also possible (and in most cases would be preferred over the above — I wouldn’t recommend doing it in the global scope, but I wouldn’t recommend doing anything in the global scope):