Inside the function, you have:

for (i=1; i<6; i++) {

Which sets a new property, i, on the global/window object.

Using with, it would set the new property on the o object

as in:

with (o) {
  eval ("i = 5"); /// <<< sets o.i = 5, not global.i = 5
}

> function(o) {
>  o.writeln('<head>');
>  o.write('<title>');
>  o.write(obj.title);
>  o.writeln('</title>');
>  o.writeln('<body>');
>  for (i=1; i<6; i++) {  // <<<<<<<<<<<<<<<<<<<< sets a global property!
>    o.write('<div>Line #');
>    o.write(i);
>    o.writeln('</div>');
>  }
>  o.writeln(</body>');
>  o.writeln(</html>');
> }


Wrapping in a function like that is a way to avoid eval() altogether, perhaps.


On Jun 12, 2013, at 4:10 AM, Andreas Rossberg <[email protected]> wrote:

> On 11 June 2013 19:56, Michael Schwartz <[email protected]> wrote:
>> [...]
>> 
>> 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);
> 
> And what's wrong with replacing this by the following?
> 
> {
> let out = ''
> function write(s) { o.out += s; },
> function writeln(s) { o.out += s + '\n'; }
> let obj = { title: 'whatever', otherMetaData: … }
> eval(script);
> }
> 
> Moreover, if the script code is generated anyway, why not simply
> generate a function like:
> 
> function(o) {
>  o.writeln('<head>');
>  o.write('<title>');
>  o.write(obj.title);
>  o.writeln('</title>');
>  o.writeln('<body>');
>  for (i=1; i<6; i++) {
>    o.write('<div>Line #');
>    o.write(i);
>    o.writeln('</div>');
>  }
>  o.writeln(</body>');
>  o.writeln(</html>');
> }
> 
> Invoke as:
> 
>  eval(script)(o)
> 
> So I don't see how your example is an argument for 'with'. Seems
> completely unnecessary.
> 
> /Andreas
> 
> -- 
> -- 
> v8-users mailing list
> [email protected]
> 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 [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
-- 
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to