Mastering JavaScript Object-Oriented Programming
eBook - ePub

Mastering JavaScript Object-Oriented Programming

Andrea Chiarelli

Share book
  1. 292 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering JavaScript Object-Oriented Programming

Andrea Chiarelli

Book details
Book preview
Table of contents
Citations

About This Book

Unleash the true power of JavaScript by mastering Object-Oriented programming principles and patterns

About This Book

  • Covering all the new Object-Oriented features introduced in ES6, this book shows you how to build large-scale web apps
  • Build apps that promote scalability, maintainability, and reusability
  • Learn popular Object-Oriented programming (OOP) principles and design patterns to build robust apps
  • Implement Object-Oriented concepts in a wide range of front-end architectures

Who This Book Is For

This book is ideal for you if you are a JavaScript developers who wants to gain expertise in OOP with JavaScript to improve your web development skills and build professional quality web applications.

What You Will Learn

  • Master JavaScript's OOP features, including the one's provided by ES6 specification
  • Identify and apply the most common design patterns such as Singleton, Factory, Observer, Model-View-Controller, and Mediator Patterns
  • Understand the SOLID principles and their benefits
  • Use the acquired OOP knowledge to build robust and maintainable code
  • Design applications using a modular architecture based on SOLID principles

In Detail

ECMAScript 6 introduces several new Object-Oriented features that drastically change the way developers structure their projects. Web developers now have some advanced OOP functionality at their disposal to build large-scale applications in JavaScript.

With this book, we'll provide you with a comprehensive overview of OOP principles in JavaScript and how they can be implemented to build sophisticated web applications. Kicking off with a subtle refresher on objects, we'll show you how easy it is to define objects with the new ES6 classes. From there, we'll fly you through some essential OOP principles, forming a base for you to get hands-on with encapsulation.

You'll get to work with the different methods of inheritance and we'll show you how to avoid using inheritance with Duck Typing. From there, we'll move on to some advanced patterns for object creation and you'll get a strong idea of how to use interesting patterns to present data to users and to bind data. We'll use the famous promises to work with asynchronous processes and will give you some tips on how to organize your code effectively.

You'll find out how to create robust code using SOLID principles and finally, we'll show you how to clearly define the goals of your application architecture to get better, smarter, and more effective coding. This book is your one-way ticket to becoming a JavaScript Jedi who can be counted on to deliver flexible and maintainable code.

Style and approach

This comprehensive guide on advanced OOP principles and patterns in JavaScript is packed with real-world use cases, and shows you how to implement advanced OOP features to build sophisticated web applications that promote scalability and reusability.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Mastering JavaScript Object-Oriented Programming an online PDF/ePUB?
Yes, you can access Mastering JavaScript Object-Oriented Programming by Andrea Chiarelli in PDF and/or ePUB format, as well as other popular books in Informatique & Programmation en JavaScript. We have over one million books available in our catalogue for you to explore.

Information

Year
2016
ISBN
9781785889103

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

Credits

Author
Andrea Chiarelli
Copy Editor
Charlotte Carneiro
Reviewer
Lyubomyr Rudko
Project Coordinator
Sanchita Mandal
Commissioning Editor
Wilson D'souza
Proofreader
Safis Editing
Acquisition Editor
Larissa Pinto
Indexer
Monica Ajmera Mehta
Content Development Editor
Shali Deeraj
Technical Editors
Gebin George
Production Coordinator
Nilesh Mohite

About the Author

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.

About the Reviewer

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.

www.PacktPub.com

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.
eBooks, discount offers, and more
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.

Why subscribe?

  • Fully searchable across every book published by Packt
  • Copy and paste, print, and bookmark content
  • On demand and accessible via a web browser

Preface

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.

What this book covers

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.

Who this book is for

This book is intended for developers with some knowledge and experience in JavaScript that want to deepen the OOP approach.

Conventions

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:
 var person = {}; person.name = "John"; person.surname = "Smith"; person.address = { street: "123 Duncannon Street", city: "London", country: "United Kingdom" }; 

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.

Reader feedback

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.

Customer support

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:
  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the boo...

Table of contents