« What’s with the ‘with’ statement»

I came across a bug in some actionscript lately which took a while to pinpoint in the end it was because of the use of the with statement. It appears that using the with statement on a property that's not currently defined and setting it to a value doesn't work i.e.

This does work

Actionscript:
  1. var myObj = new Object();
  2. myObj.foo = "blah";
  3. with (myObj) {
  4.     foo = "test";
  5. }

This doesn't work

Actionscript:
  1. var myObj = new Object();
  2. with (myObj) {
  3.     foo = "test";
  4. }

The documentation does clarify this, all the same this isn't intuitive and limits the power of shorthanding your code by method of using a with statement - sigh.