Beautiful JavaScript
edited by Anton Kovalyov
Copyright 2015 Anton Kovalyov. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Acquisitions Editor: Simon St. Laurent
- Editor: Allyson MacDonald
- Production Editor: Matthew Hacker
- Copyeditor: Rachel Head
- Proofreader: Rachel Monaghan
- Indexer: WordCo Indexing Services, Inc.
- Interior Designer: David Futato
- Cover Designer: Susan Thompson
- Illustrator: Rebecca Demarest
- August 2015: First Edition
Revision History for the First Edition
- 2015-08-07: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781449370756 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Beautiful JavaScript, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-449-37075-6
[LSI]
Preface
Functions are first-class citizens, syntax resembles Java, inheritance is prototypal, and (+""
) equals zero. This is JavaScript, arguably the most polarizing and misunderstood programming language in the world. It was created in 10 days and had a lot of warts and rough edges. Since then, there have been many attempts to replace it as the language of the Web. And yet, the language and the ecosystem around it are thriving. JavaScript is the most popular language in the worldand the only true language of the web platform. What made JavaScript special? Why did a language that was created in such a hurry succeed where others failed?
I believe the reasons why JavaScript (and the Web in general) survived lie in its omnipresenceits practically impossible to find a personal computer that doesnt have some sort of JavaScript interpreterand its ability to gain from disorder, to use its stressors for self-improvement.
JavaScript, like no other language, brought all kinds of different people to the platform. Anyone with a text editor and a web browser could get started with JavaScript, and many did. Its expressiveness and limited standard library prompted those people to experiment with the language and push it to its limits. People were not only making websites and applications; they were writing libraries and creating programming languages that could be compiled back into JavaScript. Those libraries competed with each other, and their approaches to solving problems often contradicted one another. The JavaScript ecosystem was a mess, but it was bursting with life.
Many of those libraries and languages are now forgotten. Their best ideas, howeverthe ones that proved themselves and stood the test of timewere absorbed into the language. They made their way into JavaScripts standard library and its syntax. They made the language better.
Then there were languages and technologies that were designed to replace JavaScript. But instead of succeeding, they unwillingly became its necessary stressors. Every time a new language or system to replace JavaScript emerged, browser vendors would find a way to make it faster, more powerful, and more robust. Once again, good ideas were absorbed into newer versions of the language, and the bad ones were discarded. These competing technologies didnt replace JavaScript; instead, they made it better.
Today, JavaScript is unbelievably popular. Will it last? I dont know. I cannot predict whether it will still be popular 5 or 10 years from now, but it doesnt really matter. For me, JavaScript will always be a great example of a language that survived not despite its flaws but because of them, and a language that brought people of so many different backgrounds into this wonderful world of computer programming.
About This Book
This book was written by people who are intimately familiar with the language. Each and every person who contributed a chapter is an expert in his or her domain. The authors highlight different sides of JavaScript, some of which you can discover only by writing lots of code, experimenting and making mistakes. As you make your way through this book, youll get to see what JavaScript movers and shakers love about their favorite language.
Youll also learn a lot. I did. But do not mistake this book for a JavaScript tutorial, because it is much bigger than that. There are chapters that challenge the conventional wisdom and show how even the most feared features can be used as helpful tools. Some authors show that JavaScript can be a tool for self-expression and a form of art, while others share the wisdom of using JavaScript in codebases with hundreds of contributors. Some authors share personal stories, while others look into the future.
Theres no common pattern that goes from one chapter to anothertheres even a purely satirical chapter. This is intentional. I tried to give the authors as much freedom as possible to see what they would come up with, and they came up with something incredible. They came up with a book that resembles JavaScript itself, where each chapter is a reflection of its author.
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
TIP
This element signifies a tip or suggestion.
NOTE
This element signifies a general note.
Using Code Examples
Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/oreillymedia/beautiful_javascript.
This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: Beautiful JavaScript, edited by Anton Kovalyov (OReilly). Copyright 2015 Anton Kovalyov, 978-1-449-37075-6.