You’ll learn which object a JavaScript call works for, how to apply decorators by hand, and how nested calls stack up.
A translation desk prices translating a museum guide: word count times a rate in pence per word.
Its counter counts price calculations. You’ll port its Python quote pipeline to JavaScript.
Here’s a first taste. The desk’s Python prices a quote as words times the rate, and
@lru_cache caches that price:
from functools import lru_cache
calculations = 0
@lru_cache(maxsize=None)
def price(words, rate_pence):
global calculations
calculations += 1
return words * rate_pence
print(price(400, 12))
print(price(400, 12))
print(calculations)
Two quotes for 400 words at 12 pence print 4800 twice, and the counter shows one calculation:
4800
4800
1
JavaScript has no lru_cache, so the port writes a wrapper, a Map keyed by each call’s arguments:
function memoize(fn) {
const cache = new Map();
return (...args) => {
if (!cache.has(args)) {
cache.set(args, fn(...args));
}
return cache.get(args);
};
}
let calculations = 0;
const price = memoize((words, ratePence) => {
calculations += 1;
return words * ratePence;
});
console.log(price(400, 12));
console.log(price(400, 12));
console.log(calculations);
The same two calls print 4800 twice, but the counter says two:
4800
4800
2
Finding that first quote again is one of the jobs ahead.
The desk’s Python script counts the words, prices and
records each request, sets up once and formats the currency. In JavaScript, there’s no @ line and
no functools: you apply each wrapper by hand, keep the object a method works for and build each
cache key yourself.
By the end of this course, you’ll be able to:
- Keep the object a method works for (its receiver) when you pass it along or save it for later
- Decorate a call with an explicit wrapper that keeps its arguments, receiver and result
- Cache only repeatable work, with a key that covers every input
- Trace nested calls on the call stack, apart from the scope chain
- Port the translation desk’s quote pipeline to JavaScript
In Python, you only need to know how to write decorators (with @wraps), use functools.partial
and @lru_cache, and follow a recursive function’s calls. In JavaScript, you only need to know
classes with this, closures, rest parameters and spread, and Map’s get(), set() and has().
You’ll need a current version of Node installed, and no packages. The examples use Node 26 and Python 3.15.
The course mixes short videos with text lessons and exercises. Every video has a summary below it. A project ports the whole pipeline, and a quiz and a summary close the course.
Next up: Finding this at the Call Site, starting from the desk’s formatter.