Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #7595 > unrolled thread

How Array.prototype.forEach Works (Test Before Explaining)

Started bydhtml <dhtmlkitchen@gmail.com>
First post2011-10-20 22:30 -0700
Last post2011-10-21 11:27 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  How Array.prototype.forEach Works (Test Before Explaining) dhtml <dhtmlkitchen@gmail.com> - 2011-10-20 22:30 -0700
    Re: How Array.prototype.forEach Works (Test Before Explaining) dhtml <dhtmlkitchen@gmail.com> - 2011-10-20 22:47 -0700
      Re: How Array.prototype.forEach Works (Test Before Explaining) "J.R." <groups_jr-1@yahoo.com.br> - 2011-10-21 11:27 -0700

#7595 — How Array.prototype.forEach Works (Test Before Explaining)

Fromdhtml <dhtmlkitchen@gmail.com>
Date2011-10-20 22:30 -0700
SubjectHow Array.prototype.forEach Works (Test Before Explaining)
Message-ID<f711147c-c7a2-4c09-843b-6e4abe411ce9@t38g2000prg.googlegroups.com>
The `this` value in the callback function in Array.prototype.forEach
is the array itself.

http://es5.github.com/#x15.4.4.18

Unfortunately, the author of what will be another book on JavaScript
doesn't want know that.
Regarding this:
http://www.youtube.com/watch?v=hs6tF-RDX4U#16:00

THis comment (mine):-
| The point of example of what `this` is in the body of that
| function. He uses the example as grounds for a language change
| proposal. The problem is that he is completely wrong in what he
| thinks the value of `this` should be. It is a false premise, so
| not grounds for a language fix. I did not watch the whole
| thing, but there are other mistakes in that video.

He thought that that comment of mine was rude and eliminated me from
the video project. Fine!

I was not to be an editor. I was to make videos. So I would be able to
work with the author to get corrected material by which to build the
video around. But how much work would that be, being an unpaid,
unacknowledged editor?

To answer that question, I had to do some research on the author's
work, see how bad it was, give some feedback in plain language (no
fluff, no insults), and see how he responded.

There were other questionable aspects with the proposal. The book
"Effective JavaScript" by Dave Herman is about EcmaScript not in a
browser context. How to explain contextual problem solving using the
language in a context-free environment? To beginners?

I searched I found the "behavior.js" script which was never a good
idea along with the video at hand. I rationalized that as an old
mistake that he could have moved on from. Then I found the recent
video, watched a bit, then I left my feedback, then boom, got my
reply.

It is very easy to turn away from a helpful critic. Really, and the
college diplomas can probably be used to try and cover the mess up.
And spam will likely cover up this message.


And that is how `Array.prototype.forEach` works.

It's a good idea run your code before posting it (or presenting it at
Google). And if you're technically wrong, it's probably forgivable; we
all make mistakes. But if you didn't run it, and you're wrong, and you
complain about the criticism, that is too bad.
--
Garrett

[toc] | [next] | [standalone]


#7597

Fromdhtml <dhtmlkitchen@gmail.com>
Date2011-10-20 22:47 -0700
Message-ID<84b0c9d9-da16-4a25-9ed4-13c9c770156e@v33g2000prm.googlegroups.com>
In reply to#7595
On Oct 20, 10:30 pm, dhtml <dhtmlkitc...@gmail.com> wrote:
> The `this` value in the callback function in Array.prototype.forEach
> is the array itself.
>
> http://es5.github.com/#x15.4.4.18
>
> Unfortunately, the author of what will be another book on JavaScript
> doesn't want know that.

Well it turns out I was wrong.

"If a thisArg parameter is provided, it will be used as the this value
for each invocation of callbackfn. If it is not provided, undefined is
used instead."

Well that's how admitting a mistake is done!
--
Garrett

[toc] | [prev] | [next] | [standalone]


#7607

From"J.R." <groups_jr-1@yahoo.com.br>
Date2011-10-21 11:27 -0700
Message-ID<12981089.341.1319221652655.JavaMail.geo-discussion-forums@yqoo7>
In reply to#7597
On Friday, 21 October 2011 03:47:47 UTC-2, dhtml  wrote:
> On Oct 20, 10:30 pm, dhtml <dhtmlk...@gmail.com> wrote:
> > The `this` value in the callback function in Array.prototype.forEach
> > is the array itself.
> >
> > http://es5.github.com/#x15.4.4.18
> >
> > Unfortunately, the author of what will be another book on JavaScript
> > doesn't want know that.
> 
> Well it turns out I was wrong.
> 
> "If a thisArg parameter is provided, it will be used as the this value
> for each invocation of callbackfn. If it is not provided, undefined is
> used instead."

Hi,
I prefer the MDN's definition at
<https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach>

"If a thisArg parameter is provided to forEach, it will be used as the this value for each callback invocation as if callback.call(thisArg, element, index, array) was called. If thisArg is undefined or null, the this value within the function depends on whether the function is in strict mode or not (passed value if in strict mode, global object if in non-strict mode)."

Cheers,
JR

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web