3 ms·
No, unfortunately. If a reference isn't found in your context object, it falls through to the ambient namespace. So say you run ... context = { foo: 1, b
by curveship 13y ago
No, unfortunately. If a reference isn't found in your context object, it falls through to the ambient namespace. So say you run ...
context = { foo: 1, bar: 2 };
with (context) {
foo = 2;
bar = 3;
}
That will probably do what you expect. But now say you run it where context is just ...
context = { foo: 1 };
with (context) {
foo = 2;
bar = 3;
}
... you might think this would add a 'bar' property to your context object, but in fact it creates a global variable bar. Whoops!
In short, 'with' is pointy on both ends.
- agumonkey 13y agoOh yeah, `with` is dangerous.