Mr. Jaya’s house gains a floor per decorator: Mrs. Yanti’s @log writes the guest book, Rizal’s @memo answers from his board, Dina’s @cek refuses a negative…
Why it matters
Decorators (a TC39 proposal that is not final, back at stage 2.7 since May 2026, yet already used by TypeScript 5 and many frameworks) attach behaviour to a method (logging, caching, validation, permissions) without mixing it into the core logic. Knowing the wrapping order means knowing why @memo over @log logs less than the other way round.
The key idea
A decorator replaces the method with a wrapper, bottom up
Common mistakes
Thinking the order of decorators makes no difference It matters a lot. The top one becomes the outermost wrapper. @memo over @log: it logs only when the board lacks the answer; the other way round: it logs every call.
Thinking a decorator changes the method’s own body No. A decorator returns a replacement function. The original body stays whole inside, and the wrapper calls it through value.call(this, …). What sits on Juru.prototype.ukur is the wrapper.
Forgetting that decorators need a class TC39 decorators attach only to a class and its members (methods, fields, accessors, the class itself), not to a loose function. The signature is (value, context), and context.kind says which kind. The @ syntax is still a proposal: in a browser that does not read it, use TypeScript or Babel, which write it out as plain functions like the panel does.
Try it in this playground
Put @memo over @log, call ukur(4) 2× The second call is answered from Rizal’s board upstairs: Mrs. Yanti below writes nothing.
Move @log above @memo Now every call is logged, also those answered by the board. The written order is the wrapping order.
Add @cek, call ukur(-2) A RangeError is thrown before Mr. Jaya works: the floors under Dina are not touched.
@log over @cek, then ukur(-2) The attempt is logged first, then refused further in. The ← … line never shows.