Typically, the with keyword is employed to simplify long namespaces, rather than simply referencing a single object. The purpose of utilizing the keyword in this context isn't clear to me. It's unlikely that the syntax parser will accept o.bad:property
, as it appears to be attempting to do in the code using with.
If the o
object in this scenario is merely a shortcut for a lengthier namespace, I would suggest stopping one step shy in the resolution process using with. Instead, you could encapsulate your property within a string like so...
var nmSpace = new Object();
nmSpace.o = { "bad:property": 1, "goodProperty": 2 };
with (nmSpace) {
alert(o['goodProperty']); // functions perfectly
alert(o['bad:property']); // now accesses "bad:property"!
}
I hope this explanation proves helpful.