CodeBlanks Logo Icon CodeBlanks

Project: Utility library

JavaScript course · Advanced · Lesson 19/100

Overview of the 5-lesson utility library project: reusable structures with class + module.

Project: Utility library

In this 5-lesson project we'll build a reusable utility library. At its center is a Collection class: it brings adding, removing and searching together in one interface.

Our roadmap:

  • Lesson 1: set up the class skeleton
  • Lesson 2: set up the internal state with the constructor
  • Lesson 3: add the add, remove and find methods
  • Lesson 4: export the class as a module
  • Lesson 5: import the module from another file and use it

Each lesson continues from the previous one's solution.

The library skeleton

A library is the sum of units used from the outside. Our unit is a single class: Collection. It wraps an array and exposes access through methods; the items array is never touched directly from outside.

In this lesson we'll only declare the empty class and add a header comment to the file. Later lessons will fill it in. The class keyword is enough to start.

Exercise Declare the empty Collection class

Add a header comment to library.js and declare an empty Collection class.

Show example solution
Write class, a space, the class name, and curly braces.

Example solution:
// Utility library
class Collection {}

Test yourself

  1. Which class brings adding, removing and searching into one interface?

    • Promise
    • Collection
    • Fetch
    • Array
    Show answer

    Collection — Correct! Collection is the central class of this project.

  2. Declare the empty class

    class ____ {}
    Show answer
    class Collection {}
  3. Match each concept to its role

    class
    defines a class
    constructor
    sets up an instance
    this
    reaches internal state
    export
    opens to a module

All lessons in Advanced