Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M6223

Callback

Callback
TechnicalHigh supportSoftware Engineering
Included
account_tree

Updated 2026-07-28

Loading revision record…

Summary

A callback function, or simply callback, is a reference to executable code in computer programming that is passed as an argument to other code; it is expected that this code will call back (execute) the callback function as part of its work. This execution can be immediate, as in synchronous callbacks, or it can occur at a later point in time, as in asynchronous callbacks. Programming languages support callbacks in different ways, often implementing them as subroutines, lambda expressions, blocks, or function pointers.

Definition

A callback function, or simply callback, is a reference to executable code in computer programming that is passed as an argument to other code; it is expected that this code will call back (execute) the callback function as part of its work. This execution can be immediate, as in synchronous callbacks, or it can occur at a later point in time, as in asynchronous callbacks. Programming languages support callbacks in different ways, often implementing them as subroutines, lambda expressions, blocks, or function pointers.

How to use

A callback function, or simply callback, is a reference to executable code in computer programming that is passed as an argument to other code; it is expected that this code will call back (execute) the callback function as part of its work. This execution can be immediate, as in synchronous callbacks, or it can occur at a later point in time, as in asynchronous callbacks. Programming languages support callbacks in different ways, often implementing them as subroutines, lambda expressions, blocks, or function pointers.

Mechanism

A callback passes a function as an argument, and when a future event completes, the system calls it, implementing 'do it when the event arrives'. It hands control back to the framework (inversion of control), so the caller does not have to wait synchronously; it is the basis for asynchronous and plugin-based design.

Practice

In progress 0/5

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

Cases

  • A timer executes a callback when it expires; an event listener responds to a click.

Common pitfalls

  • Applying synchronous thinking to asynchronous callbacks causes timing bugs; forgetting to unregister causes memory leaks.
Sources

Source support: Explicit

References currently contain only Wikipedia links; primary sources still need review.

  • link
    zh.wikipedia.orghttps://zh.wikipedia.org/wiki/%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0ZH · Explicit
    verified
account_treeGenealogyexpand_more

RELATED MODELS