[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Found anb example in a bok but foreachIn does not exist

Tony Johansson

12/31/2014 4:28:00 PM

Here is a function that I have found in a book called "Eloquent JavaScript"
but forEachIn does not exist in JavaScript.
How would I changed it so that it works. At the bottom I have give example
how I call this dom function

function dom(name, attributes /*, children...*/)
{
var node = document.createElement(name);
if (attributes)
{
forEachIn(attributes, function (name, value) {
node.setAttribute(name, value);
});
}

for (var i = 2; i < arguments.length; i++)
{
var child = arguments[i];
if (typeof child == "string")
child = document.createTextNode(child);
node.appendChild(child);
}

return node;
}

document.body.appendChild(
dom("p", null, "A paragraph with a ",
dom("A", {href: "http://ericsso...}, "link"),
"inside of it."));

//tony

10 Answers

Evertjan.

12/31/2014 6:44:00 PM

0

"Tony Johansson" <johansson.andersson@telia.com> wrote on 31 dec 2014 in
comp.lang.javascript:

> Here is a function that I have found in a book called "Eloquent
> JavaScript" but forEachIn does not exist in JavaScript.
> How would I changed it so that it works.

Eloquence isn't a sign of quality.

If a function in such a book does not "work",
the best thing to do is

1 to throw the book away,
probably you can still do this this year.

2 define what you want such new function to do.

2 build this function from scratch.

You cannot do worse than using a function that does not work,
and that you yourself don't understand, and cannot explain,
how it should work.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Christoph M. Becker

12/31/2014 6:56:00 PM

0

Tony Johansson wrote:

> Here is a function that I have found in a book called "Eloquent
> JavaScript" but forEachIn does not exist in JavaScript.
> How would I changed it so that it works.

Maybe you're looking for:
<http://eloquentjavascript.net/1st_edition/chapter8.html....

--
Christoph M. Becker

Scott Sauyet

1/2/2015 6:23:00 AM

0

Evertjan. wrote:
> Tony Johansson wrote:
>
>> Here is a function that I have found in a book called "Eloquent
>> JavaScript" but forEachIn does not exist in JavaScript.
>> How would I changed it so that it works.
>
> Eloquence isn't a sign of quality.

I disagree. Eloquence is not definitive proof of quality, but it
is one useful sign.

But beyond that, do you have a substantive critique of the book?

I've used it to help teach beginning JS programmers. I think it's
one of the better ones around. I don't remember seeing any reviews
of it here, but I have not been paying very much attention for the
last year.

Have you read it? At least some versions of it are freely available
on the web.


> If a function in such a book does not "work",
> the best thing to do is
>
> 1 to throw the book away,
> probably you can still do this this year.
>
> 2 define what you want such new function to do.
>
> 2 build this function from scratch.

3. Look for earlier definitions in the book for the missing parts.

Christoph M. Becker's response has already done that for the OP. Such
a response is more informative and IMHO better for the group than a
snide disparagement of the book in question.

Evertjan.

1/2/2015 8:29:00 AM

0

Scott Sauyet <scott.sauyet@gmail.com> wrote on 02 jan 2015 in
comp.lang.javascript:

> Evertjan. wrote:
>> Tony Johansson wrote:
>>
>>> Here is a function that I have found in a book called "Eloquent
>>> JavaScript" but forEachIn does not exist in JavaScript.
>>> How would I changed it so that it works.
>>
>> Eloquence isn't a sign of quality.
>
> I disagree. Eloquence is not definitive proof of quality, but it
> is one useful sign.

We are talking about self-declared eloquence, which should make you
suspicious.

> But beyond that, do you have a substantive critique of the book?
>
> I've used it to help teach beginning JS programmers. I think it's
> one of the better ones around. I don't remember seeing any reviews
> of it here, but I have not been paying very much attention for the
> last year.
>
> Have you read it? At least some versions of it are freely available
> on the web.

The fact that the OP as a beginner should be subjected to code that does not
show which used functions are JS-native, and which are to be found elsewhere
in the book, does not give me much confidence.


>> If a function in such a book does not "work",
>> the best thing to do is
>>
>> 1 to throw the book away,
>> probably you can still do this this year.

It is clear the book is needlessly complex for the OP.

I have never heard of a JS-book that was not:
outdated, incomplete, full of errors, error-prone, overselfconfident, etc.

JS should better [imho, but that is always implied] be learned than taught.
learned by specs, example, trial and error, where the 'teacher' is absent of
does not want to express superior knowledge.

If found that is true for most other subjects too, believing in a revered
teacher usually sets you of on the wrong foot.

>>
>> 2 define what you want such new function to do.
>>
>> 2 build this function from scratch.
>
> 3. Look for earlier definitions in the book for the missing parts.

One really should not have to do that, such definitions should be
backpointed.

> Christoph M. Becker's response has already done that for the OP. Such
> a response is more informative and IMHO better for the group than a
> snide disparagement of the book in question.

Now you are talking, rubish I mean, as

1 why should a responce be "good for the group"?

2 why should a responce be informative?

3 why should a response be be compared with an 'already' one, also given the
nonsequential nature of the usenet server system?

4 what is wrong with a 'snide disparagement'?

All that is required according to netiquette and charter, is 'on topic',
meaning 1 about JS in general or 2 about the NG.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Michael Haufe (\"TNO\")

1/2/2015 3:07:00 PM

0

On Friday, January 2, 2015 12:23:13 AM UTC-6, Scott Sauyet wrote:
> I've used it to help teach beginning JS programmers. I think it's
> one of the better ones around. I don't remember seeing any reviews
> of it here, but I have not been paying very much attention for the
> last year.

I agree it is one of the better ones available as an introduction to the language. There hasn't been a review here, only a debate on whether the FAQ should include book suggestions (The answer was "No" or "Undecided" IIRC), but that was around the time the debate around FAQ maintenance was occurring.

> Have you read it? At least some versions of it are freely available
> on the web.

<http://eloquentjavascrip...

Michael Haufe (\"TNO\")

1/2/2015 3:15:00 PM

0

On Friday, January 2, 2015 2:28:56 AM UTC-6, Evertjan. wrote:

> I have never heard of a JS-book that was not:
> outdated, incomplete, full of errors, error-prone, overselfconfident, etc.

Then I suggest reading David Herman's book: "Effective JavaScript"

Scott Sauyet

1/2/2015 4:13:00 PM

0

Evertjan. wrote:
> Scott Sauyet wrote:
>
>> But beyond that, do you have a substantive critique of the book?
>>
>> I've used it to help teach beginning JS programmers. I think it's
>> one of the better ones around. I don't remember seeing any reviews
>> of it here, but I have not been paying very much attention for the
>> last year.
>>
>> Have you read it? At least some versions of it are freely available
>> on the web.
>
> The fact that the OP as a beginner should be subjected to code that does not
> show which used functions are JS-native, and which are to be found elsewhere
> in the book, does not give me much confidence.

This book is a tutorial, not a reference. I think that makes a big
difference. A careful reader would have seen that function many times
between when it was introduced and when it was used here.

But I'm assuming that this is a no. You haven't read the book?


> It is clear the book is needlessly complex for the OP.

It is only clear to me that the OP ran into an issue and asked
for input from this group. The rest is interpretation.


> I have never heard of a JS-book that was not:
> outdated, incomplete, full of errors, error-prone, overselfconfident, etc.

There are better and worse books, though. This one, along
with David Herman's _Effective Javascript_ are my most-recommended
ones. That's why I was trying to tease out whether you had a
serious critique of it. I have of course seen flaws, but on the
whole, I find this a worthwhile book for beginning and intermediate
Javascript programmers.


> JS should better [imho, but that is always implied] be learned than taught.
> learned by specs, example, trial and error, where the 'teacher' is absent of
> does not want to express superior knowledge.
>
> If found that is true for most other subjects too, believing in a revered
> teacher usually sets you of on the wrong foot.

Do you think your preferred learning style should dictate how others
choose to learn?


>> 3. Look for earlier definitions in the book for the missing parts.
>
> One really should not have to do that, such definitions should be
> backpointed.

I agree; at least once in the current chapter it should point to the
definitions of any functions its using from previous ones. I don't
think Haverbeke does so. But I don't think it's a significant flaw.


>> Christoph M. Becker's response has already done that for the OP. Such
>> a response is more informative and IMHO better for the group than a
>> snide disparagement of the book in question.
>
> Now you are talking, rubish I mean, as
>
> 1 why should a responce be "good for the group"?

Participating in a community in a way that undermines that community
is a good definition of trolling. If that's what you prefer to do,
I guess we have little more to say to one another.


> 2 why should a responce be informative?

It doesn't have to be. It could also be humorous. But if it's
neither, then I for one am not interested in it. Maybe others are.


> 3 why should a response be be compared with an 'already' one, also given the
> nonsequential nature of the usenet server system?

The "already" explained why I didn't do so myself. It was not meant
to take you to task for not having done so.


> 4 what is wrong with a 'snide disparagement'?

It's snide. And it's a disparagement.


> All that is required according to netiquette and charter, is 'on topic',
> meaning 1 about JS in general or 2 about the NG.

I responded because I didn't know if behind the snark you had
a substantive critique of a book I admire. I would have found
that worth hearing. Otherwise I would have dismissed your post
as mere noise. I guess I should have done so.

-- Scott

Evertjan.

1/2/2015 4:52:00 PM

0

Scott Sauyet <scott.sauyet@gmail.com> wrote on 02 jan 2015 in
comp.lang.javascript:

> It is only clear to me that the OP ran into an issue and asked
> for input from this group. The rest is interpretation.

Eh?

So how can something be clear to you without your interpretation?
That must be out of dogmatic believe, I suppose?

What is wrong with interpretation, anyway?

>> 1 why should a response be "good for the group"?

> Participating in a community in a way that undermines that community
> is a good definition of trolling.

Whay nonsense, you are out of line concerning the use of usenet by redefining
it as a sort of helpdesk.

Responses that are not "enhancing the group" are not per se "undermining" the
group, as long as they follow usenet netiquette and group charter.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Christoph M. Becker

1/2/2015 11:05:00 PM

0

Scott Sauyet wrote:

> Evertjan. wrote:
>> Scott Sauyet wrote:
>>
>>> But beyond that, do you have a substantive critique of the book?
>>>
>>> I've used it to help teach beginning JS programmers. I think it's
>>> one of the better ones around. I don't remember seeing any reviews
>>> of it here, but I have not been paying very much attention for the
>>> last year.

No, there has not been a review of this book ("Eloquent JavaScript" by
Marijn Havebeke) during the last year in this newsgroup -- it has not
even been mentioned before this thread.[1]

>> 4 what is wrong with a 'snide disparagement'?
>
> It's snide. And it's a disparagement.

Very well said. :)

[1] Telling from what my Usenet provider actually provides.

--
Christoph M. Becker

Christoph M. Becker

1/2/2015 11:19:00 PM

0

Michael Haufe (TNO) wrote:

> On Friday, January 2, 2015 2:28:56 AM UTC-6, Evertjan. wrote:
>
>> I have never heard of a JS-book that was not:
>> outdated, incomplete, full of errors, error-prone, overselfconfident, etc.
>
> Then I suggest reading David Herman's book: "Effective JavaScript"

Thanks for the suggestion. As Scott Sauyet has also recommended this
book, I've ordered a copy.

--
Christoph M. Becker