Practical Modern JavaScript
by Nicols Bevacqua
Copyright 2017 Nicols Bevacqua. 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://oreilly.com/safari). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Editor: Allyson MacDonald
- Production Editor: Melanie Yarbrough
- Copyeditor: Kim Cofer
- Proofreader: Molly Ives Brower
- Indexer: Wendy Catalano
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Rebecca Demarest
Revision History for the First Edition
- 2017-06-26: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781491943533 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Practical Modern JavaScript, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author 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-491-94353-3
[LSI]
Foreword
When I created JavaScript in 1995 at Netscape, I had no definite idea that it would become the most widely used programming language on the Internet. I did know that I had very little time to get it into minimum viable shipping state, and so I made it extensible and mutable from global object on down, even to base-level meta-object protocol hooks (e.g., toString
and valueOf
, styled after Javas methods of the same names).
Yet in spite of its ongoing evolution and still-rising popularity, JavaScript always benefits from an incremental and careful teaching approach that puts first things first. I think this follows inevitably from the hurried design and intentional extensibility. I overloaded two kernel elements, functions and objects, so that programmers could use them in various ways as general workalikes for individual tools in a larger Swiss army knife. This meant that students would need to learn which tool was best to use for a specific task, and how precisely to wield that particular blade.
Netscape was a whirlwind for me, and I think for anyone there from early 1995 on. It was rushing toward an initial public offering predicated on competing with Microsoft via the infamous Netscape + Java kills Windows formula repeated by Marc Andreessen on the IPO roadshow that year. Java was the big-brother or Batman programming language to little-brother, Robin the boy hostage sidekick scripting language, JavaScript.
But I knew while I was writing the first version (code-named Mocha) that JavaScript and not Java would be integrated deeply with the Netscape browser and the Document Object Model I created at the same time. There was no way across the Netscape/Sun organizational boundary, or the browser/JVM code bases, to embed Java other than as a plugin.
So I did have a vague sense that JavaScript would either succeed over time and do well, or else fade quickly in the shadow of something else. I remember telling my friend and cubicle-mate Jeff Weinstein, when he asked me what Id be doing in 20 years, that it would be JavaScript or bust. Even then I felt a sense of deep obligation to JavaScripts users that was inherent in the two-blade Swiss army knife design I had chosen under the dual constraints of extremely short schedule and make it look like Java management edict.
The Modular JavaScript book series fulfills my hope for an incremental and straightforward pedagogy, starting with easily applicable code examples and scaling through design patterns to entire module-based applications. This series nicely covers best testing practices and winning techniques for deploying JavaScript applications. It is another jewel in OReillys crown of books on JavaScript.
I am delighted to support Nicols endeavor because his book looks exactly like what people who are coming to JavaScript with fresh eyes need. I first met Nicols at a dinner in Paris and got to know him a bit there, and over time online. His pragmatism combined with empathy for newcomers to the language and a great sense of humor convinced me to review this book in draft form. The finished work is easy to digest and fun. I encourage you to dive in, to discover and embrace JavaScript, and to contribute to developing a better web for everyone.
Brendan Eich, Inventor of JavaScript, CEO and cofounder of Brave Software
Preface
Back in 1998, when I was using FrontPage for all my web development needs at school, if someone had told me that Id end up working on the web for a living, I wouldve probably chuckled. JavaScript has grown along with us in all the years since, and its hard to imagine how the web couldve thrived without it. Bit by bit, this book will give you a comprehensive picture of the modern JavaScript landscape.
Who Should Read This Book
This book is meant for web developers, enthusiasts, and professionals with a working knowledge of plain JavaScript. These developers and anyone looking to further their understanding of the JavaScript language shall benefit from reading