JavaScript·Intermediate·Coding·1 min read
What values must a robust wrapper preserve?
Short interview answer
It should preserve the caller's this value and latest arguments, return semantics where meaningful, and clearly define timing behavior. TypeScript utilities should also preserve the original function's parameter types.
Example
function throttle(fn, interval) { let last = 0; return function (...args) { const now = Date.now(); if (now - last >= interval) { last = now; return fn.apply(this, args); // keep `this` and pass args through } };}Key takeaway
Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.