Unit 10: Object Oriented Programming and TDD

Overview

In this unit, we will discuss JavaScript's brand of OOP by introducing constructors and the prototype chain. Constructors are special functions that are extremely useful in creating objects of similar types. Prototypes are JavaScript’s built in system, allowing objects to inherit features from other objects. Prototypes are considered by many to be an advanced JavaScript topic and mastering it will be sure to give you an extra edge as a JavaScript developer.

We will cover test driven-development (TDD). When practicing TDD, we first write tests for application features before writing any code. Then, we write only the minimum amount of code needed to make the tests pass and repeat this process until the application is complete. Test-driven development has numerous benefits but ultimately helps us write more understandable and maintainable code.

We will conclude this unit with an introduction to modern class syntax and inheritance. ES6 introduced a class keyword which allows us to create objects using class structures similar to those found in other OOP programming languages. Under the hood, classes are just constructor functions with more intuitive syntax. They allow us to implement more advanced OOP patterns such as inheritance without needing to understand all of the nuances of JavaScript's prototypal inheritance system.

Key Topics

  • Objects

  • this

  • Callbacks

  • Constructors

  • Prototypes

  • TDD

  • Unit Tests

  • Classes

  • Inheritance

Comprehension Check

You will be employer-ready if you can answer the following questions:

  1. What is a constructor function and how would you use one?

  2. What is the difference between classical inheritance and prototypal inheritance?

  3. What are some benefits of test-driven development?

Learning Objectives

You will be employer-competitive if you are able to:

  • Integrate constructor functions into your applications, adding structure to your code and reducing the amount of code you have to write.

  • Build entire applications using OOP, separating data and functionality into different constructor functions that can be composed together.

  • Verify your code works as intended through the use of automated tests.

  • Build applications using test-driven-development, writing tests before implementing functionality.

  • Utilize modern ES6 class syntax to implement more advanced OOP patterns such as inheritance.

  • Create more scalable applications that follow the OOP paradigm.

Homework: Word Guess With Constructors

  • In this unit's assignment, you will create a Word Guess command-line game using constructor functions.

Helpful Links