Jump to content



Photo

The Javascript Book

javascript book

  • Please log in to reply
11 replies to this topic

#1 Bill

Bill

    Member

  • Members
  • PipPip
  • 38 posts

Posted 20 October 2011 - 6:04 PM

Hi Larry

A topic I would like to see in your JavaScript book is multidimensional arrays. As I want to know how to add, update and delete an array of JavaScript custom objects. It would therefore be good to see a specific example of this in your book. Why you may well ask?

Recently, I have been attempting to modify a nutrition program that I found on the internet to this end but to no avail. The JavaScript nutrition program I am referring to adds up all the various totals for eight nutrient values including protein, fats and carbohydrates from the various food groups - very useful for the health conscious. This also involves a user selecting the amount for each food item from a drop down list. Anyway, here is part of the list of array objects:

foodgroup[1]=new food("Apple Juice",15,0,0,59,0,125,1,3);
foodgroup[2]=new food("Prune Juice",24,0,0,99,3,301,1,4);
foodgroup[3]=new food("Grapefruit Juice",11,0,0,44,0,208,1,2);
foodgroup[4]=new food("Cranberry Juice",19,0,0,76,0,15,1,3);
				 -
				 -
foodgroup[101]=new food("Vegetable Oil 8.1 cal/cc",0,0,27,2430,0,0,0,0);

The problem that I have discovered occurs when you want to change the data structures in the list of array objects in anyway. If you want to add a food group, delete a food group that you don’t eat anymore or change the nutirent data values themselves with more accurate data, it can become a very cumbersome and tedious process. It can take a fair while, even hours and days especially if you have 29 nutrients or more! This could be expedited in my opinion with the inclusion of add, update and delete buttons within the user interface itself. Nevertheless, this nutrition program uses JavaScript coding like document.write to output results. You mentioned in one of your articles that this is “bad code, bad JavaScript“ but I have found it to be a very useful program despite it limitations in terms of changing the code to increase the number of nutrients etc.

You can see this JavaScript program I am referring to hereby just pasting the following link in your browser: http://www.nafwa.org...d-software.html and then download the file NUTRIENT.ZIP

Regards
  • 0

#2 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4,000 posts
  • LocationState College, PA (USA)

Posted 2 November 2011 - 10:39 AM

Thanks for the suggestion and sorry for the delayed reply. I will be covering multidimensional arrays in the book, but thanks for making the interest clear.

As for document.write, no, you should not be using that, you should be using DOM manipulation techniques instead.
  • 0

#3 Josee

Josee

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts

Posted 17 February 2012 - 6:16 AM

Hello, everyone,

Peachpit (the publisher of Larry's books) has the following offer at the moment:

Offer valid through February 21, 2012. PRESIDENT coupon provides 40% discount off the list price of two, or 50% off on three eBooks or videos, or any combination of eBooks and videos. PRESIDENT coupon may not be combined with any other offer, and is not valid for book + eBook bundles or eBook Deal of the Week featured titles.


I'm just mentioning this because it applies to Larry's JavaScript book (ebook version only). Although its official publication date is 22 February and it's only on pre-order yet, you can include it in the two or three ebooks entitled to this discount.

In case you hadn't guessed, I'm really looking forward to reading this book!
  • 1

#4 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4,000 posts
  • LocationState College, PA (USA)

Posted 18 February 2012 - 5:10 PM

Hey, Josee. Thanks for sharing this. I had no idea. I'm putting it in my newsletter, which I'm about to send out!
  • 0

#5 Josee

Josee

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts

Posted 21 February 2012 - 8:22 AM

Sadly, I've just cancelled my order, for in the meanwhile I've discovered that Peachpit and I don't have the same conception of e-books. To them, e-books are apparently just pictures of printed books that you can read on a computer, iPad, etc. To me, they should be numerical books that I can use as I want, which means
— adding bookmarks,
— adding links within the file and with other files,
— copying a few lines to paste them in another file.

You can't do any of these things in their PDFs. To be fair, you can add comments and notes, which is good. But it's not enough for me, especially when I've made a point of buying the books, instead of just looking for pirate versions on the web.
  • 0

#6 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4,000 posts
  • LocationState College, PA (USA)

Posted 21 February 2012 - 8:24 AM

Sorry about that. Still, thanks for letting everyone know about the discount.
  • 0

#7 Jason

Jason

    Newbie

  • Members
  • Pip
  • 13 posts
  • LocationPerth, Australia

Posted 21 February 2012 - 8:43 AM

Printed books are always the best for technical books I feel. I always forget which ebooks I have. Peachpit have crazy ebook prices as well, they maybe living in the past in that sense sadly. I'll be getting my copy through Ullman Publications, whenever they get their store up and running :P

Out of interest, Have ebook sales been increasing over the past couple of years Larry? I like buying the ebook+print combo from publishers when they are fair about it.
  • 0

#8 Josee

Josee

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts

Posted 21 February 2012 - 10:22 AM

That's really a matter of taste, of course. I never forget which ebooks I have, and for programming books I really prefer ebooks. As I've got a large screen, I keep the ebook on one side of the screen, my text editor next to it, and can easily alternate between reading and testing.

I've also discovered that I can't change the file preferences so as to choose the zooming factor once for all, and indicate where I stopped reading so that the file opens at the right page on the next day.

Did you say "they may be living in the past"? With a vengeance! (Mine…)
  • 0

#9 Jason

Jason

    Newbie

  • Members
  • Pip
  • 13 posts
  • LocationPerth, Australia

Posted 21 February 2012 - 10:34 AM

Of course, each to their own. I tend to read tech books away from the computer then come back to it later to do the examples. Have you written to Peachpit about the ebooks? Probably best to do that, who knows, they may actually listen.
  • 0

#10 Josee

Josee

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts

Posted 21 February 2012 - 10:41 AM

Oh, yes, I wrote, cancelling the order and explaining precisely why.

Well, that's one book for which I'll be reading the printed version!
  • 0

#11 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4,000 posts
  • LocationState College, PA (USA)

Posted 21 February 2012 - 9:18 PM

Sadly, I've just cancelled my order, for in the meanwhile I've discovered that Peachpit and I don't have the same conception of e-books.


In Peachpit's defense, I would say that while we like to blame companies for certain practices we don't like, a company is just a group of people. Like all people, they will sometimes get things wrong. I believe that Peachpit is doing it's best to try to navigate this dynamic and somewhat difficult landscape that keeps changing. They are trying to figure this out, and they will make mistakes. But I know they have good intentions. Clearly, conveying to them what you want and don't want will help them to make better decisions in the future.

And keep in mind, that it's very much in my best interest for Peachit to release e-books that readers like (i.e., I'm not trying to let Peachpit off the hook). I have absolute no control over them, but my name is on the book, so a bad e-book reflects poorly on me. But we're watching companies try to take a technology--printed books--that has been around for 500 years and convert it to a technology that's been around for 10. There are going to be growing pains.

But it's not enough for me, especially when I've made a point of buying the books, instead of just looking for pirate versions on the web.


I don't think you do yourself or your arguments any favors when you mention the ability to pirate media. The arguments for actually buying books and against stealing them have nothing to do with features or wants. It's a simple moral argument: pirating media is wrong. This comment reminds me of a Chris Rock joke about people bragging about not doing things they aren't supposed to do.

Josee, to be clear, I very much appreciate your interest in my books and that you have needs that aren't being met. I also appreciate that you're communicating what you want to the publisher. But I read a hostility here, and in the email you also forwarded to me, that seems disproportional to the problem itself. Could be just me (again, the email factors into my saying this).

Printed books are always the best for technical books I feel. I always forget which ebooks I have. Peachpit have crazy ebook prices as well, they maybe living in the past in that sense sadly. I'll be getting my copy through Ullman Publications, whenever they get their store up and running :P


Thanks, Jason. Very much appreciated. Personally, I like a physical book, especially with technical books and even more so with programming books. The idea of reading a Visual QuickStart/QuickPro Guide on a Kindle, for example, is impractical to me. But I can see Josee's perspective with having PDFs that are on the screen while you're programming, and the ability to copy and paste code.

Now about this Ullman Publications... I should start by coming up with a catchy name!

Out of interest, Have ebook sales been increasing over the past couple of years Larry? I like buying the ebook+print combo from publishers when they are fair about it.


Good question. I can't speak for my own books, in that I haven't looked into it much. But a bigwig at the Publisher told me that e-books were growing at a very high rate, like nearly doubling every year, but they're still at a relatively low rate, like 10% or so (kind of like how Apple has nearly doubled their desktop market share, bringing them up to like 8%).
  • 0

#12 Josee

Josee

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts

Posted 26 February 2012 - 8:41 AM

Hello, Larry,

I don't think that "a bad e-book reflects poorly" on you or any author. It reflects badly on publishers. And I can't see any other reason, on their part, for selling protected PDFs than trying to avoid pirate versions. Which they don't. That's just the point I'm trying to make: given the number of pirate versions on the web, pirates have obviously found ways round the protections. These protected PDFs are only annoying to ordinary, paying customers who just want to use a book as a book, and a computer as a computer. I don't think there's any justification to treating all e-book readers as potential thieves just because a few of them may be.

I finally bought the Kindle version. It's just as bad, from my point of view, as a protected PDF (the limitations are more or less the same), but the printed version is not yet available in France and no date is given. I was just surprised to find that reading a Kindle version on a computer (I haven't got a Kindle) is actually better in some ways than reading a PDF, because the Kindle version is "responsive": it adapts to the viewport width.
  • 0