![]()
Mastering JavaScript Object-Oriented Programming
![]()
Mastering JavaScript Object-Oriented Programming
Copyright Š 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: June 2016
Production reference: 1220616
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78588-910-3
www.packtpub.com
![]()
![]()
Andrea Chiarelli has over 20 years of experience as software engineer and technical writer. Throughout his career, he has used various technologies for the projects he was involved in, ranging from C# to JavaScript, ASP.NET to AngularJS, and REST to PhoneGap/Cordova.
He has contributed to many online and offline magazines, such as Computer Programming and ASP Today and has coauthored a few books published by Wrox Press.
Currently, he is a senior software engineer at the Italian office of Apparound Inc., a mobile software company founded in the heart of Silicon Valley, and he is a regular contributor to HTML.it, an Italian online magazine focused on web technologies. You can contact him at https://www.linkedin.com/in/andreachiarelli
I wish to thank my family for their support, patience and love.
![]()
Lyubomyr Rudko is Senior Software Engineer, and has been developing large web application with JavaScript for the last 6 years. He has great experience in AngularJS, BackboneJS, React.js and Sencha ExtJS. Lyubomyr is a big fan of JavaScript language and truly enjoys sharing his skills and experience with others. Currently, he is working as a Team Technical Lead for Lohika (http://www.lohika.com/elite-teams/). You can contact him at https://ua.linkedin.com/in/lyubomyrrudko.
![]()
eBooks, discount offers, and more
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at
www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
[email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
- Fully searchable across every book published by Packt
- Copy and paste, print, and bookmark content
- On demand and accessible via a web browser
![]()
It is now a fact that JavaScript is the most widely used language in the world. Born as a simple glue between the user and the HTML, it has evolved over the years and has acquired an increasingly important role. Today, its scope is no longer just the Web browser, but it lives also on the server, on the desktop PC, on mobile devices up to embedded devices. JavaScript is no longer a simple language to write some scripts, but a language to create complex applications.
Unfortunately, many believe that JavaScript cannot compete with programming languages such as C ++, Java or C #. Many developers with a traditional OOP background think that JavaScript does not have the characteristics to be considered a true Object-Oriented language. This book aims to disprove this prejudice and to show that JavaScript has the characteristics to be considered a true OOP language, although with its peculiarities that make it unique. Thanks to the latest innovations introduced by the ECMAScript standard, we will see how we can write robust and efficient code with JavaScript and we can apply those typical principles of Object-Oriented Programming to create scalable and maintainable applications.
Chapter 1, A Refresher of Objects, recalls some basic concepts about objects management in JavaScript covering literal objects, constructor functions and classes.
Chapter 2, Diving into OOP Principles, shows that JavaScript supports all the basic principles that allows us to define it a true OOP language.
Chapter 3, Working with Encapsulation and Information Hiding, describes some techniques to protect private members of an object, implementing Encapsulation and Information Hiding principles.
Chapter 4, Inheriting and Creating Mixins, covers the inheritance mechanism of JavaScript based on prototypes and the creation of mixins.
Chapter 5, Defining Contracts with Duck Typing, focuses on using duck typing instead of relying on type checking and shows some techniques to emulate classical OOP interfaces.
Chapter 6, Advanced Object Creation, discusses some different ways to create objects and introduces a few Design Patterns such as the Factory Pattern and the Builder Pattern.
Chapter 7, Presenting Data to the User, explores the most common Presentation Patterns such as Model View Controller Pattern and Model View ViewModel Pattern.
Chapter 8, Data Binding, explains how to implement Data Binding and describes Patterns such as the Observer Pattern and the Publisher/Subscriber Pattern.
Chapter 9, Asynchronous Programming and Promises, discusses the issues with asynchronous programming in JavaScript and shows how to overcome them with Promises and other innovative techniques.
Chapter 10, Organizing Code, analyzes the various approaches to organize JavaScript code in modules: from the classical IIFE to the latest ECMAScript 6 modules.
Chapter 11, SOLID Principles, explores how to apply the five SOLID Design Principles in order to create scalable and maintainable applications.
Chapter 12, Modern Application Architectures, describes the most common architectures for JavaScript applications and introduces the Facade and Mediator Patterns.
![]()
What you need for this book
Most of the code provided in this book is not bound to a specific JavaScript runtime environment, so it could run in any JavaScript environment. However some examples are specific for the Web browser environment, so the console of Web Inspector such as Chrome Developer tools or Firebug is needed.
![]()
This book is intended for developers with some knowledge and experience in JavaScript that want to deepen the OOP approach.
![]()
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."
A block of code is set as follows:
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
For this book we have outlined the shortcuts for the Mac OX platform if you are using the Windows version you can find the relevant shortcuts on the WebStorm help page https://www.jetbrains.com/webstorm/help/keyboard-shortcuts-by-category.html.
![]()
Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail
[email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at
www.packtpub.com/authors.
![]()
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
- Log in or register to our website using your e-mail address and password.
- Hover the mouse pointer on the SUPPORT tab at the top.
- Click on Code Downloads & Errata.
- Enter the name of the boo...