On May 31, 2012, at 9:31 PM, Brendan Eich wrote:
> This may seem not much of a difference, but it's major not only due to the
> typo and array-not-an-Array-instance cases. The scope chain extension is
> costly and forces deoptimization in common implementations. And of course
> 'with' is banned in strict mode.
>
> Dave, any other differences to spell out?
That's pretty much it, but I'd also point out one more important consequence:
by `with` adding an object to the scope chain, it pollutes scope with
potentially unintended properties of the object -- or any of its prototypes. So
when you have a variable reference in a sub-expression, you may think you know
what it refers to but it could be captured by the `with` object or one of its
properties.
var obj = {
log: console.log.bind(console),
foo: function() { Object.prototype.bar = "captured" }
};
var bar = "local variable";
with (obj) {
log(bar); // local variable
foo();
log(bar); // captured
}
Whereas with cascades, you'd get:
var obj = {
log: console.log.bind(console),
foo: function() { Object.prototype.bar = "captured" }
};
var bar = "local variable";
with (obj) {
log(bar); // local variable
foo();
log(bar); // local variable
}
Dave
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss