Using 'with' keyword for DSLs ?

Using 'with' keyword for DSLs ?


Hi devs,
this is a topic that pops regularly to my mind. I believe most
javascripters have stopped looking at the "with" statement when they
found out how unclear variable assignation is (cf.
http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/
). But it strikes to me that if you avoid that later case, "with" can
be really useful to build DSLs. Consider :
jQuery.$ = jQuery; // for backward-compat.
with(jQuery) {
ready(function() {
find("H1").hide("slow");
});
}
I'm not debating the elegance of the chosen function names. What I
would like to show is that here we can use jQuery functions as if they
where in the global space, but without pollution. jQuery has that
tendance (provoking) of pushing everything in the $ function,
precisely because of global space pollution.
Another usage is cloaking undesirable variables. Here comes the fake
sandbox that shouldn't be considered secure but that could become
useful for json evalutation, or just for creating another environment
stripped with some browser features.
function Sandbox() {
(for k in window)
this[k] = undefined;
}
with(new Sandbox) {
alert( document.title ) // => undefined
}
Any thoughts ? Missing something ?
Cheers,
zimbatm