Because they are a different class of error. They're NOT an error using with.
The less error prone for the end user, the better.
On Jun 12, 2013, at 10:11 AM, Andreas Rossberg wrote:
> On 12 June 2013 18:48, Michael Schwartz wrote:
>> strict mode does not work in the real world where templat
On 12 June 2013 18:48, Michael Schwartz wrote:
> strict mode does not work in the real world where templates are concerned.
>
> Students don't want to see your compiled function. They may be designers,
> not programmers. Likely are.
>
> Showing them a JavaScript error is simply the incorrect th
strict mode does not work in the real world where templates are concerned.
Students don't want to see your compiled function. They may be designers, not
programmers. Likely are.
Showing them a JavaScript error is simply the incorrect thing to do.
And it's perfectly valid to let them clobber a
On 12 June 2013 18:27, Michael Schwartz wrote:
> In the real world, your solution doesn't work.
Are you saying that strict mode does not work in the real world? Then
I beg to differ.
> Like I said, you get a few hundred students of varying skills creating
> templates. Many will just cut&paste
In the real world, your solution doesn't work.
Like I said, you get a few hundred students of varying skills creating
templates. Many will just cut&paste from existing templates, etc.
"use strict" works on the compiled template.
Throwing a run time error or showing the end user the compiled sc
On 12 June 2013 17:35, Michael Schwartz wrote:
> How is the template compiler to figure out i is a global reference?
>
> LOTS of code.
>
> That's the point. The template compiler could be 50 lines using with.
IIUC, you don't want 'i' to pollute the global name space? Then don't
use an undeclared
How is the template compiler to figure out i is a global reference?
LOTS of code.
That's the point. The template compiler could be 50 lines using with.
On Jun 12, 2013, at 8:01 AM, Andreas Rossberg wrote:
> On 12 June 2013 15:05, Michael Schwartz wrote:
>> Inside the function, you have:
>>
On 12 June 2013 15:05, Michael Schwartz wrote:
> 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
So just generate 'o.i' instead of 'i' there. ;)
/Andreas
--
--
On Wed, Jun 12, 2013 at 1:10 PM, Andreas Rossberg wrote:
> 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);
> }
>
i
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('');
> o.write('
On 11 June 2013 19:56, Michael Schwartz 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);
>
The best use case I can think of for "with" is in templates.
Consider ejs style template:
<%= obj.title %>
<% for (i=1; i<6; i++) { %>
Line #<%= i%>
<% } %>
This gets "compiled" into a script like:
writeln('');
write('');
write(obj.title);
writeln('');
writeln('');
for (i=1; i<6; i++) {
wri
On 11 June 2013 18:11, Michael Schwartz 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.
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.
Granted v8 doesn't optimize code using it.
On Jun 11, 2013, at 9:06 AM, Stephan Beal wrote:
> On Tue, Jun 11, 2013 at 5:53 PM, Michael Schwartz
On Tue, Jun 11, 2013 at 5:53 PM, Michael Schwartz wrote:
> with (o) {
>
Yeah, i was hoping to avoid the 'with'. i assume there is no
clean/portable/sane way to do this in JS, and to be honest the idea never
occurred to me until today while tinkering on my own pet scripting engine
(which, by an a
Ugly but…
In JavaScript you can do something like this:
var o = { dbRow: whatever, rowNumber: whatever, colNames: whatever, colCount:
whatever };
with (o) {
function rowCallback() {
// dbRow would be accessible without the o. prefix, etc.
}
}
On Jun 11, 2013, at 8:30 AM, Andreas Rossbe
On 11 June 2013 17:11, Stephan Beal wrote:
> Please consider this construct:
>
> function rowCallback(dbRow){
> // Notes below ref to this scope
> }
>
> myDbDriver.query({
> sql:"SELECT * FROM T",
> callback: rowCallback
> });
>
> That hypothetical code would run the given query and call the
Hi, all,
Please consider this construct:
function rowCallback(dbRow){
// Notes below ref to this scope
}
myDbDriver.query({
sql:"SELECT * FROM T",
callback: rowCallback
});
That hypothetical code would run the given query and call the given
callback for each row. What i would like to do h
18 matches
Mail list logo