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

D

dhtml

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:

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.
 
D

dhtml

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!
 
J

J.R.

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 thisvalue 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top