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

var myObj = new Object();
myObj.foo = "blah";
with (myObj) {
    foo = "test";
}

This doesn't work

var myObj = new Object();
with (myObj) {
    foo = "test";
}

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.