From: Thomas 'PointedEars' Lahn on
Garrett Smith wrote:

> Richard Cornford wrote:
>> Asen Bozhilov wrote:
>>> Garrett Smith wrote:
>>>> Example #4
>>> I was give answer TypeError on this question.
>> For a system that does not implement a - substr - method for strings?
>
> DMD Script, maybe?

The DMDScript source code in D indicates that it implements
String.prototype.substr():

<http://www.digitalmars.com/dscript/>


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
From: kangax on
On 2/19/10 8:10 PM, Richard Cornford wrote:
> Garrett Smith wrote:
>> Yet another JS Quiz:
>> http://www.nczonline.net/blog/2010/02/16/my-javascript-quiz/
>>
>> I have a couple of comments on the explanations provided:
>> http://www.nczonline.net/blog/2010/02/18/my-javascript-quiz-answers/
>>
>> Example #1:
>> I believe the explanation is that the postfix is matched, as in:
>>
>> TOKENS: num1, ++, +, num2;
>
> That is an explanation, but not a full explanation because it does not
> state why +++ must be interpreted as the tokens ++ followed by the token
> +, rather than + followed by ++. The answer to that is in the spec, in
> the last sentence of the first paragraph of section 7, where it says
> "The source text is scanned from left to right, repeatedly taking the
> longest possible sequence of characters as the next input element". So
> given +++, the longest possible sequence of characters that can be a
> token is ++, leaving the last + to be the next token.

This also explains why something like `x+++++x` can not be parsed as if
it was `x++ + ++x`. First, `++` that follows `x` is consumed. Next
longest token is again `++`, leaving only `+` and `x`. The whole
sequence becomes: `x`, `++`, `++`, `+`, and `x` (`x++ ++ +x`), which is
obviously not a valid program. As soon as we prevent 3rd and 4th (or
even just 4th) `+` from becoming one token, expression parses as
expected: `x+++ ++x`.

[...]

--
kangax
From: Asen Bozhilov on
Richard Cornford wrote:
> Asen Bozhilov wrote:

> > I was give answer TypeError on this question.
>
> For a system that does not implement a - substr - method for strings?

Exactly. `String.prototype.substr' isn't part from any editions of
ECMA-262 standard. On this questions `TypeError' is possible answer.
Another possible answer is: "I don't know." and again is correct
answer.

| 2 Conformance
| [...]
| In particular, a conforming implementation of
| ECMAScript is permitted to provide properties not described in this
specification,
| and values for those properties,
| for objects that are described in this specification.

The standard permit methods like `substr', but these methods are
implementation depended, because concrete implementation can implement
in own way. I don't think methods like `substr' should be part from
quizzes, because confuse readers, especially when author of quiz isn't
specified concrete environment.




From: Asen Bozhilov on
Richard Cornford wrote:

> That is an explanation, but not a full explanation because it does not
> state why +++ must be interpreted as the tokens ++ followed by the token
> +, rather than + followed by ++. The answer to that is in the spec, in
> the last sentence of the first paragraph of section 7, where it says
> "The source text is scanned from left to right, repeatedly taking the
> longest possible sequence of characters as the next input element". So
> given +++, the longest possible sequence of characters that can be a
> token is ++, leaving the last + to be the next token.

How can you explain:

var x = 10;
+++x;

There SyntaxError instead of runtime error.

From: Jorge on
On Feb 19, 10:38 pm, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
>
> Example #2:
> The explanation provided mentions scope, and that is totally wrong. The
> scope of the anonymous function expression wrapped in the setTimeout is
> (anonymous)[[Scope]] --> doIt [[Scope]] -- global [[Scope]].

Yep, every function carries its context with it, that's what closures
are about, and as soon as a reference to a function survives longer
than the context in which it was created (as when saved in the
setTimeout queue), a closure is born.

> The answer as to why `this.x` === 5 is explained by the fact that the
> execution context for the nonstandard `setTimeout` method is global context.

No. Not at all. It's explained by the fact that "this" is === window.
It has nothing to do with the execution context. It could have been
very well any other context !== the global one, and still "this" would
have been "window". E.g. if you wrapped it into yet another function.
--
Jorge.