The best use case I can think of for "with" is in templates.

Consider ejs style template:

<head>
<title><%= obj.title %></title>
</head>
<body>
<% for (i=1; i<6; i++) { %>
<div>Line #<%= i%></div>
<% } %>
</body>
</html>

This gets "compiled" into a script like:
writeln('<head>');
write('<title>');
write(obj.title);
writeln('</title>');
writeln('<body>');
for (i=1; i<6; i++) {
write('<div>Line #');
write(i);
writeln('</div>');
}
writeln(</body>');
writeln(</html>');

Invocation might be something like:

var o = {
  out: '',
  write: function(s) { o.out += s; },
  writeln: function(s) { o.out += s + '\n'; }
  obj: { title: 'whatever', otherMetaData: … }
};
with (o) {
   eval(script);
}
...
document.write(o.out);

The for loop instantiates a global variable if you don't use "with".

The use of "with" allows you to define write() and writeln() functions that the 
template writer can call directly if they choose.

The template writers may be hundreds of students sharing the same system.  You 
ask for problems allowing them to clobber globals accidentally.

JSLint or other solution doesn't make sense because the compiled script doesn't 
look anything like the source.  You can turn a trivial 50 line JavaScript 
template compiler into thousands of lines to catch errors like that.  Seriously 
though, why if you can do it in 50?

I've only been programming for 40 years and writing JavaScript almost 
exclusively for the past 8 or so.  What you call "poo," I do not.

My initial comment was aimed at the decision to deprecate it in the first 
place, to make it illegal in strict mode and then carry on further with 
excising it from the language.


On Jun 11, 2013, at 9:20 AM, Andreas Rossberg <rossb...@google.com> wrote:

> On 11 June 2013 18:11, Michael Schwartz <myk...@gmail.com> wrote:
>> I never understood why "with" is considered a bad thing.  It's got a bad
>> reputation, though it has some real world use cases that make a lot of
>> sense.
> 
> One thing to realise is that every pile of poo in any language can be
> motivated by use cases. That is a vastly insufficient criterium for
> being good. ;)
> 
>> Granted v8 doesn't optimize code using it.
> 
> And ES5 strict mode disallows it, and consequently, any modular ES6
> code will as well.
> 
> /Andreas
> 
> -- 
> -- 
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> --- 
> You received this message because you are subscribed to the Google Groups 
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to