
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
NOTE: MY POSTINGS REFLECT MY OWN VIEWS AND DO NOT NECESSARILY REPRESENT THE VIEWS OF MY EMPLOYER, ACCENTURE.
DIFFICULTY LEVEL: BEGINNER to ADVANCED
NOTE: I consider this to be a Beginner to Advanced book as it contains material that even expert level developers will use in their day-to-day work.
JavaScript - The Good Parts
by Douglas Crockford Publication Date: May 2008 ISBN-13: 978-0596517748 ISBN-10: 0596517742 http://javascript.crockford.com/ https://en.wikipedia.org/wiki/Douglas_Crockford (This is a review of my hard-copy of this book, but the electronic version is the same except for the dog-eared pages! 😀) |
|
I originally wrote this review on 9-29-2016 and wondered if it were still a relevant review. Guess what?! It is! So, I did a bit of judicious editing (it needed an editor - um, like me, to look it over). So, here we go! Picking up where my original article started.
I have been intending to write this particular article for some time now, but I keep getting distracted by other topics! So, finally, here it is!
Frankly speaking, I consider this particular book to be the "Gold Standard" of the JavaScript language! Gush! Gush! 😃
First, let me do a bit of explanation. Douglas Crockford is a major contributor to the JavaScript language. He is credited with popularizing the JSON format. And, he-wrote-this-book!
So, for me, this made me interested in what the book had to say. I mean, the guy who helped define the language ought to know what he is talking about, right?
I ordered my copy online and didn't pay too much attention as to content (it was recommended by a friend that I get a copy). When it showed up and I took it out of the shipping box...and was surprised! What-the-heck!?! It was only about 5/8" of an inch thick! And, yes, I did measure it. My first thought: I've been ripped off!
Well, I am glad to say, that particular thought vaporized the minute I opened the book. Inside was a clean, concise, well written (yes, even entertaining) book on the JavaScript language.
Pretty much every important aspect of the language is covered, and examples (code-snippets) are provided. Geez, examples, and good ones! And they mostly work in Global on ServiceNow!
So what's in the book?
Crockford breaks out the language into seven general topics (in ten chapters), and then drills down on each with detail on specific "good" features. Yep! There are ten chapters; see my description of each and you will understand. Oh, and yeah, he is referencing the movie "The Good, The Bad, and the Ugly" in his laying out of the book. A favorite of mine, btw!
Chapter 1 - Introduction. Here the author explains why and when you would use JavaScript, and a bit of history on its development.
Chapter 2 - Grammar. You can't have a language without the basics. Here you will find names, numbers, strings and all that.
Chapter 3 - Objects. One of my favorite chapters. This is one of the core power-tools of JavaScript. Crockford does an outstanding job of going over object definitions, referencing, and much more. His explanation of prototypes is excellent and is directly applicable to ServiceNow Scripting. There are lots of examples here. The author also covers some interesting little-discussed features such as: Delete and Global Abatement (these only work in Scoped Applications and then only if you set it up for ECMA 2021).
Chapter 4 - Functions! Another of the core power-tools of JavaScript. Here the author describes these in detail; covering most of the features you will probably ever need to use in your day-to-day development job. Function Objects, literals, arguments, recursion (I bold this because it is a super topic to learn, and I know many a programmer that shies away from the topic), callbacks, and a LOT more. There are excellent examples of every aspect that is presented.
Chapter 5 - Inheritance In my previous book report (Book Report - Principles of Object Oriented JavaScript) I covered a book that described this and other Object Oriented (OO) features of the JavaScript language. JavaScript is not an OO language, but it does have a couple of OO features. One of these is inheritance. Here Crockford covers how to model inheritance (think AJAX Script Includes) using the built-in features: Prototypes, and Functions. Do you see a progression here by the author? Each chapter builds off the next. Nicely done.
Chapter 6 - Arrays. One of my favorite topics to write about. This chapter you will want to read through a couple of times. He covers all the typical language definitions: literals, length, enumeration, dimensions. However, the author doesn't stop there but includes: deletion of array elements, methods, and an interesting section on confusion. I have used several of these examples in my client work. Highly useful!
Chapter 7 - Regular Expressions. This chapter is not a tutorial on regular expressions, but instead covers how to use regular expressions in JavaScript. Several nice examples!
Chapter 8 - Methods. This is a really great chapter! Honest! Here you find most of the super useful built-in functions of JavaScript described WITH examples! Some of them pretty in-depth. Gold! I found that these translate well into ServiceNow Scripting.
Chapter 9 - Style. Here the author touches briefly on coding standards, and how to avoid the most common errors associated with things like formatting. Indentation and readability can really be a problem in any language. Of all the chapters I felt that this one probably should have been expanded further to include more examples, and pitfalls.
Chapter 10 - Beautiful Features. A short wrap-up chapter where the author describes his thoughts on JavaScript, and a direction he adopted to employ more advanced features.
Despite the title, Crockford put in a couple of appendices on the warts: The awful (his wording), and the bad parts of the language. These should have been combined to form a chapter on what NOT to do! I highly recommend memorizing these examples, and employing them in your standards as things to avoid!
The awful: This should have been titled: The Ugly, but he might have run afoul of some movie rights. Covered items are: GLOBAL VARIABLES (my feeling is that this should go in the bad features), scope (I don't know how many times I have been bit by this), the overloaded plus feature ( + ), floating point, NaN (for something funny check out: Wat), and many more. Some examples, but frankly he does fine with his descriptions.
The bad: Interestingly Crockford mentions ==, and != as evil. 😀 After reading his description and reasoning I would have to say I agree. Also: eval, continue, switch fall-through (I love/hate this feature of switch, and use it a lot). ++, --, bitwise operations, and a bunch more. With examples. Nasty stuff! Bet you use some of it in your code! 😁
Crockford also throws in a couple of appendices covering JSLint (which he created); a super-great JavaScript testing tool, and JSON (which he popularized heavily). Of course both topics are well covered, and have examples. Crockford even throws in a complete JSON parser written in JavaScript! Niiiiiiiiice!
For those of you who are into computer language design, Crockford has even provided a serious break-out of syntax diagrams throughout the book, and in an appendix. This is a great example of a computer language definition.
So, here is how much of a nerd I am: I read this thing twice through after receiving my copy, and it sits dog-eared on my desk for quick referencing (yeah, I use it even above w3schools).
BTW, it has a terrific index making it really easy to look things up (don't worry you will have it all memorized after reading it through a couple of times anyway...right?!).
It is amazing how much material is packed into such a thin tome. For those of you wanting to take your scripting skills to the next level this is a must have. I highly recommend you purchase a copy of this really useful book!
Side-Note: It used to be that anyplace in ServiceNow where the Script Editor was present you could type the following and it would pop the syntax error: "eval is evil!" Which was a direct quote from p.122 of the paperback book (description of eval). Yep, that is where it comes from! 😀 ServiceNow has modified the editor so now it does not scream about this. Good!
eval('gs.info("---> Hello World")');
Side-Side-Note: Also, you might want to search the Script Includes and see how many times eval is used! It is a very interesting exercise!
Side-Side-Side-Note: Concerning eval. I agree with the author on eval to a point. It is a highly useful feature and has analogs in other languages. It is a necessary feature in most. He does caveat it. He places eval in the good parts core of the book, and in the bad parts appendices (for good reasons). It certainly can be used for evil! 😁
Anyway, in conclusion, AN AWESOME BOOK that any SERIOUS developer in ServiceNow MUST have in their library. Period. End-of-discussion. Just saying!
Enjoy!
Steven Bell.
If you find this article helps you, don't forget to log in bookmark it, and mark it as "Helpful"!
Originally published on: 9-29-2016 07:55 AM
I updated the code and brought the article into alignment with my new formatting standard.
- 1,814 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.