Object-Oriented JavaScript in JavaScript

Object-Oriented JavaScript = how to build many similar objects from one plan.

This chapter has 2 lessons and 10 exercises you run and check in your browser. Plan on about 48 minutes.

After this chapter, you can:

  • Build many objects from one class.
  • Keep data safe with private fields and getters.
  • Share code with extends and super.
  • Let different classes answer the same method in their own way.

Every lesson has short explanations, code boxes you edit and run in the live editor, and a web page example you can click.

Before you start, finish Async Concepts.

Next chapter: DOM Manipulation.

Lessons in this section

  1. Object-Oriented JavaScript

    Object properties and methods, accessing, adding, removing and displaying members, constructor functions with new and this, classes with constructors, instance properties and instance methods, and static methods and properties.

    • Create objects with properties and methods, and read, add, change and remove their members
    • Display objects with console.log(), JSON.stringify() and Object.entries()
    • Write constructor functions and create instances with new
    • Explain what this refers to inside a constructor and inside a method
  2. Core OOP Principles

    Encapsulation with public members, private # fields and data hiding; inheritance with parent and child classes and extends; polymorphism through method overriding; and abstraction that hides implementation details behind a small interface.

    • Explain encapsulation and tell public members apart from private members
    • Protect data with private # fields and expose it through methods and getters
    • Build a child class from a parent class with extends and super
    • Override methods so that one method name produces different behaviour in each class