Home›Lea Verou›Article

Mass function overloading: why and how?

Lea Verou · Feb 10, 2021

One of the things I’ve been doing for the past few months (on and off—more off than on TBH) is rewriting Bliss to use ESM 1. Since Bliss v1 was not using a modular architecture at all, this introduced some interesting challenges. Bliss is essentially a collection of helper functions. Most of these functions have a number of different signatures, to allow for more compact, readable code. The functions can be used for single things (one element, one set of arguments) or they can operate en masse (arrays of elements, object literals with multiple key-value pairs). As you might guess, this practice has been strongly inspired by the heavy use of overloading in jQuery, which was one of the driving factors behind its huge success.

For example, let’s take $.style(). It can be used to set a single CSS property, on a single element, being a rather thin abstraction over element.style:

It can also be used to set a single CSS property on multiple elements:

Keep reading

Out of respect for the author only the opening is shown here. Read the rest on the original site, or in HorizonReader with highlights, notes and AI help.

More from Lea Verou

Nudeps: bundler-like imports, none of the baggage

The goal is light-build, not no-build You npm install a package (e.g. vue), you write import { createApp } from "vue", and it works — as long as there is a bundler in between. Without one, the browser has no idea what "vue" is: it only unde

Candidate Statement for the 2026 W3C TAG Election

Group photo of the W3C TAG in July 2022 with me to the left of Sir Tim Berners-Lee (inventor of the Web and TAG chair emeritus). Photo credit: Dan Appelquist I had the great honor of being elected to the TAG by the W3C membership in 2020 an

The best way to use icons in Web UIs

TL;DR? Jump to demo I’ve always had a soft spot for icons1. Not only do they add polish to a UI, they can also tangibly improve usability. Familiar icons help users find what they need quickly, since we recognize pictures much faster than w

The best dark mode toggle is probably none

About a month ago, I wrote an article recommending that if you are going to have an always visible control for switching between light and dark mode, it should be a two-state toggle that alternates between system and whatever the current op

Dark mode toggles: two states are enough

A good two-state toggle can actually express all three data model states. Until recently, if you looked at most websites with a theme toggle1, you’d find three options: Light, Dark, and System. Examples of tri-state dark mode toggles. In (L