Loading video player…

Welcome to the Translation Desk's Quote Pipeline

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:

Language: Python
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:

Language: Program Output
4800
4800
1

JavaScript has no lru_cache, so the port writes a wrapper, a Map keyed by each call’s arguments:

Language: JavaScript
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:

Language: Program Output
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.

Download

Sample Code (.zip)

12.3 KB
Download

Course Slides (.pdf)

1012.2 KB

00:00 Welcome to JavaScript’s this, Decorators, and the Call Stack for Pythonistas! You’ll learn which object a call works for, apply decorators by hand, and follow nested calls.

00:12 A translation desk prices a museum guide’s translation: word count times pence per word. Its counter counts price calculations. You’ll port its Python quote pipeline to JavaScript.

00:25 The desk’s Python prices a quote as words times the rate, and @lru_cache caches that price. Two quotes for 400 words at 12 pence print 4800 twice.

00:37 One calculation. JavaScript has no lru_cache, so the port writes a wrapper: a Map keyed by each call’s arguments. The same two calls print 4800 twice.

00:51 But the counter says two.

00:54 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.

01:06 In JavaScript, you apply wrappers and build cache keys yourself.

01:12 You’ll keep the object a method works for and decorate calls. You’ll cache only repeatable work and trace nested calls. Then you’ll port the whole pipeline.

01:26 In Python, you need decorators, partial(), lru_cache and recursion. In JavaScript, you need classes, closures, rest and spread, and maps.

01:37 The examples use Node 26 and Python 3.15.

01:43 Videos mix with text lessons and exercises. Every video has a summary below it. A project, a quiz and a summary close the course. Next up: Finding this at the Call Site, starting from the desk’s formatter.

Become a Member to join the conversation.