Tagged articles
closure
55 articles · Page 1 of 1
This article explains PHP closures, showing their basic syntax, how to use them as function arguments, and how to generate dynamic functions at runtime with clear code examples that illustrate creating reusable and adaptable anonymous functions.
Callbackanonymous functionclosure
0 likes · 5 min read

This article explains Python decorators—from basic analogies and the underlying concepts of higher‑order functions and closures to practical examples like timing and logging decorators—showing how to enhance functions dynamically without altering their source code while preserving metadata with functools.wraps.
Code ExampleDecoratorHigher-order function
0 likes · 8 min read

The article walks through four incremental designs—from naïve println! logging to an enum‑based, zero‑allocation approach—showing how each step reduces latency in Rust, with benchmark numbers dropping from ~1769 ns to ~128 ns, and explains the reasoning, code, and trade‑offs.
EnumLoggingRust
0 likes · 12 min read

This article explains Python decorators with clear analogies, walks through the underlying concepts of higher‑order functions and closures, provides practical code examples such as timing and logging decorators, discusses common pitfalls like lost metadata, and shows how to preserve it using functools.wraps.
Best practiceHigher-order functionPython
0 likes · 10 min read

This article demystifies Objective‑C blocks by explaining their definition, practical uses, syntax variations, common usage scenarios, underlying data structures and compilation process, copy semantics, variable capture rules, reference‑cycle pitfalls, and provides concise code examples and reference links for iOS developers.
BlocksObjective-C++closure
0 likes · 15 min read

This article explains what Python closures are, how they capture outer‑scope variables, demonstrates typical patterns such as data hiding, stateful counters, factory functions, callbacks and lazy evaluation, and highlights important pitfalls like memory use and late‑binding bugs.
CallbackPythonclosure
0 likes · 9 min read

This article explains what Python closures are, how they capture surrounding variables, their key characteristics, and demonstrates multiple practical patterns—including decorators, memoization, and factories—through clear code examples and usage guidelines.
DecoratorPythonTutorial
0 likes · 10 min read

This article explains how PHP closures can capture external variables, demonstrates practical examples of wrapping reusable logic in anonymous functions, and shows how to combine closures with object‑oriented programming to improve code reuse and maintainability.
Anonymous FunctionsPHPclosure
0 likes · 5 min read

This article explains Python closures and decorators, detailing their definitions, formation conditions, practical examples, common use cases, and how decorators rely on closures, while providing code snippets for counters, timing, and repeatable execution.
DecoratorFunction WrappingPython
0 likes · 14 min read

This comprehensive guide explains JavaScript closures, covering their definition, memory‑leak risks, loop pitfalls, private variables, this binding, module pattern, static scope, performance impact, and currying, each with clear answers and practical code examples for front‑end interview preparation.
InterviewJavaScriptclosure
0 likes · 17 min read

This article explains why backend developers are moving from PHP to Go, demonstrates how Go's built-in concurrency primitives like sync.WaitGroup and errgroup simplify high‑traffic live‑streaming services, and warns about common closure pitfalls when launching goroutines in loops.
ConcurrencyGoclosure
0 likes · 10 min read

This article explains how PHP closure functions can encapsulate reusable code blocks, demonstrates basic closure syntax, shows how to pass closures for data processing, and illustrates combining closures with object-oriented programming to enhance flexibility and maintainability.
PHPclosureobject-oriented
0 likes · 4 min read

This article explains the inner workings of Python closures by tracing how nested functions are compiled into bytecode, how the CPython VM creates cell objects, binds them via the func_closure field, and stores variables in the localsplus array for static access.
CPythonFunctionPython
0 likes · 18 min read

This article explains the DRY principle in PHP and demonstrates how to create and apply closure functions for reusable code blocks, including examples with simple calculations, data processing callbacks, and integration with object‑oriented programming to improve flexibility and maintainability.
OOPPHPbackend development
0 likes · 5 min read

This article explains Python decorators, covering their definition as higher‑order functions, essential concepts like closures, step‑by‑step examples of basic, parameterized, class‑based, and stateful decorators, as well as practical uses such as logging and caching, all illustrated with clear code snippets.
CachingDecoratorHigher-order function
0 likes · 6 min read

Function Object Programming (FOP) in PHP leverages the Closure class to treat functions as first‑class objects, offering code reuse, modularity, performance gains, and testability, with examples of creating, invoking, and applying closures in higher‑order functions and callbacks.
Function ObjectsPHPbackend development
0 likes · 4 min read

This article explains how PHP closures can be used to encapsulate reusable code blocks, demonstrates practical examples including simple closures, passing closures as callbacks, and combining closures with object‑oriented programming to improve code reuse and maintainability.
closurecode reuse
0 likes · 5 min read

This article explains how PHP closure functions can be used to encapsulate reusable code blocks, demonstrates practical examples including simple arithmetic, data processing with callbacks, and integration with object‑oriented programming to improve code maintainability and flexibility.
OOPPHPclosure
0 likes · 4 min read


21CTOApr 9, 2024 · Fundamentals
Go 1.22 changes the for‑loop variable scope so that each iteration receives its own copy, eliminating the long‑standing closure pitfall that caused incorrect outputs in concurrent programs and simplifying range usage for developers.
GoGo 1.22closure
0 likes · 6 min read

This article explains the DRY principle in PHP, introduces closure functions, and demonstrates how to wrap reusable code blocks—including data processing and object‑oriented examples—using closures to improve maintainability and flexibility.
closurereusable code
0 likes · 4 min read

This article explains the concepts of callbacks, anonymous functions, and closures in PHP, providing definitions, practical examples, and demonstrating how to implement sorting with callback functions, create inline anonymous functions, and use closures to capture external variables, highlighting their benefits for code reuse and readability.
CallbackPHPanonymous function
0 likes · 7 min read

This article explains PHP closure functions, covering their definition, syntax, typical use cases such as event handling, asynchronous programming and functional programming, provides code examples, discusses advantages, cautions, and demonstrates how closures improve code clarity and flexibility.
PHPbackend developmentclosure
0 likes · 4 min read

This article explains PHP closure functions, covering their definition, typical use cases such as event handling, asynchronous and functional programming, detailed syntax examples, usage patterns, precautions, advantages, and a practical example of handling asynchronous results.
BackendPHPclosure
0 likes · 4 min read

The article explains Go closures, shows how capturing loop variables by reference can cause bugs like repeated values, demonstrates correct patterns such as copying variables inside loops or passing them as parameters, and offers guidelines to avoid common pitfalls with defer and concurrency.
GoPitfallanonymous function
0 likes · 11 min read


政采云技术Mar 21, 2023 · Frontend Development
This article explains how the this keyword is bound in JavaScript, covering default, implicit, explicit, new, and arrow‑function bindings, and demonstrates the concepts with practical debounce examples and code snippets to show how the calling context determines the value of this.
JavaScriptclosuredebounce
0 likes · 12 min read

This article explains Gradle's domain‑specific language (DSL), compares Groovy and Kotlin DSL syntax, and introduces Groovy closures with practical code examples, helping developers grasp build script fundamentals and migrate between Groovy and Kotlin Gradle scripts.
DSLGradleGroovy
0 likes · 16 min read

This article explains the compatibility challenges between Java functional interfaces and Groovy closures, introduces a utility class that converts Supplier, Function, Predicate, and Consumer into Groovy closures, and provides a complete code example with demonstration and output.
BackendFunctional InterfaceGroovy
0 likes · 5 min read

This article explains how C/C++ function pointers work, demonstrates their compiled address, shows why they lack context, introduces a closure struct to bundle code with data, and relates this pattern to C++'s std::function for storing callables with captured environment.
C++CallbackFunction Pointer
0 likes · 6 min read

This article explains Python decorators—from basic closure equivalents to factory‑style registry usage—showing how they register modules, modify function behavior, handle parameters, support multiple decorators, and can decorate both functions and classes, all with clear code examples.
Factory Patternadvanced-pythonclosure
0 likes · 8 min read

This article explains Python decorators by first introducing the concept of closures, then demonstrating basic and advanced decorator implementations—including logging, timing, class-based decorators, and the use of functools.wraps—while also covering decorator execution order and providing annotated code examples.
FunctionPythonclosure
0 likes · 7 min read

This article explains free variables, defines closures in ECMAScript, shows why every function is a closure, and provides practical examples—including common interview pitfalls and solutions—illustrating how closures capture and preserve lexical scope in JavaScript.
Free VariableIIFEJavaScript
0 likes · 5 min read

This article demystifies JavaScript closures, explains how V8 builds scope chains and closure objects during compilation, and demonstrates why closures can cause memory leaks by retaining references, illustrated with multiple runnable code examples and practical debugging tips.
JavaScriptMemory LeakV8
0 likes · 14 min read

This article provides an in‑depth exploration of Swift closures on iOS, covering their definition, three forms, practical use cases, underlying SIL generation, capture lists, context capture, storage mechanisms, escaping and autoclosure variants, and important memory‑management considerations such as reference cycles.
Capture Listautoclosureclosure
0 likes · 17 min read

This article explains JavaScript's variable scope models—including lexical and dynamic scope—covers the three scope types (global, function, and block), details hoisting, the eval function, scope chains, and closures, and shows practical code examples for each concept.
closureevalhoisting
0 likes · 18 min read

This article explains what Objective‑C blocks are, why they are useful, how to declare and use them in various contexts, and dives into the compiler‑generated data structures, copy/dispose mechanisms, __block semantics, memory‑management pitfalls, and reference‑cycle avoidance.
BlocksCompilerObjective-C++
0 likes · 13 min read

This article explains how to achieve Go‑style asynchronous execution in Java and Groovy by leveraging closures, the java.util.function.Supplier interface, custom thread‑pool wrappers, and Phaser‑based synchronization, complete with practical code examples and a custom ThreadFactory implementation.
ConcurrencyGroovyJava
0 likes · 7 min read

This article explains Python's closure late-binding behavior that causes unexpected lambda results, demonstrates the issue with a sample interview question, and presents four practical solutions—including default‑argument binding, functools.partial, generator expressions, and yield‑based lazy evaluation—to achieve the intended outputs.
FunctionPythonclosure
0 likes · 4 min read

This article explains the historical concept of activation objects in ECMAScript 1/3, why they disappeared after ES5 in favor of lexical environments, how the idea persists as a generalized abstraction similar to stack frames, and how it relates to closures.
Activation ObjectECMAScriptJavaScript
0 likes · 9 min read

This article explains the historical concept of Activation (or Variable) Objects in ECMAScript 1/3, why they disappeared after ES5, how modern JavaScript uses Lexical Environments as their successor, and how this relates to closures and function execution.
Activation ObjectECMAScriptJavaScript
0 likes · 8 min read

This article explains the historic concept of Activation (or Variable) Objects in ECMAScript 1/3, how they were replaced by Lexical Environments in ES5+, and how the broader notion still helps understand closures and stack frames in modern JavaScript.
Activation ObjectECMAScriptLexical Environment
0 likes · 9 min read

This article explains JavaScript’s scope types, execution context, activation objects, and the lifecycle of functions, illustrating how closures retain memory, how garbage collection works, and provides practical solutions for common closure pitfalls in React functional components.
Frontend DevelopmentJavaScriptReact
0 likes · 12 min read

This article demonstrates how to use PHP namespaces with the `use` keyword, create aliases for classes, functions, and constants, incorporate traits, and capture variables in anonymous functions, providing clear code examples for each concept.
aliasclosurenamespace
0 likes · 2 min read

This article explains the PHP Closure class, its bind and bindTo methods, how to control $this and scope when copying anonymous functions, and provides multiple code examples—including common pitfalls and a Composer autoload trick—to help developers master closure binding in backend development.
BINDanonymous-functionbindTo
0 likes · 8 min read

This article explains what Python decorators are, how they work as closures to extend function behavior without altering source code, and provides clear examples—including basic syntax, syntactic sugar with @, execution timing, common use cases, and advanced patterns such as parameterized, multi‑decorator, and class‑based decorators.
Code Examplesclosuredecorators
0 likes · 9 min read

This article explains how to create a counter using Python closures, explores three different implementations—including mutable objects, generators, and the nonlocal keyword—while clarifying the behavior of immutable vs. mutable objects and demonstrating the practical use of nonlocal in nested functions.
Pythonclosurefundamentals
0 likes · 7 min read

This article explains the middleware design pattern in JavaScript, illustrating recursive and chainable implementations with Koa and Redux, and explores techniques such as function composition, reduceRight, parameter passing, and the role of currying and closures.
CurryingJavaScriptRedux
0 likes · 11 min read

This article explains the concept of closures, showing how a function can capture external variables, illustrated with Scala examples that demonstrate anonymous functions, free variables, and a complete runnable program producing expected output.
Scalaclosurefunctional
0 likes · 3 min read

This article provides a comprehensive guide to Python functions, scopes, variable lifecycles, closures, and decorators, illustrating each concept with clear explanations and runnable code examples, and shows how to create flexible, reusable decorators using @ syntax, *args, and **kwargs.
DecoratorFunctionargs
0 likes · 22 min read

An in‑depth look at a common interview puzzle that prints “0 1 2 3 3 3”, explaining how JavaScript’s asynchronous setTimeout, function scope, and closures interact, why the output occurs, and how to modify the code to achieve the expected 0‑1‑2 sequence.
ES5ES6JavaScript
0 likes · 5 min read

This article explains how setTimeout works in JavaScript, covering its two parameters, the unique timer ID, the event‑queue execution after the call stack clears, and how closures can be used to preserve loop indices for correct output.
JavaScriptclosureevent-loop
0 likes · 5 min read

This article explains how Groovy parses Android-specific DSL in Gradle build files, covering DSL benefits, command chains, operator overloading, delegate mechanisms, and step‑by‑step execution of buildscript, repositories, dependencies, and tasks to help developers customize their Android build process.
AndroidDSLGradle
0 likes · 9 min read


21CTOApr 16, 2016 · Frontend Development
This article demystifies JavaScript closures by presenting a minimal demo, explaining how closures differ from regular functions, illustrating their role in memory management, and showcasing advanced patterns like immediately‑invoked function expressions for practical module creation.
ConceptJavaScriptclosure
0 likes · 7 min read


21CTOMar 15, 2016 · Frontend Development
This article dissects jQuery’s source code, revealing its clear modular architecture, closure-based sandbox, innovative no‑new instantiation, extensive method overloads, extend mechanisms, chainable calls with stack tracking, regex optimizations, and conflict‑resolution strategies, offering developers deep insights into its design and performance.
JavaScriptclosuredesign patterns
0 likes · 16 min read


21CTOMar 8, 2016 · Frontend Development
This article explains the fundamental differences between scope and context in JavaScript, covers variable scope, execution contexts, the scope chain, closures, module patterns, call/apply/bind methods, and ES6 arrow functions, providing clear code examples for each concept.
BINDContextES6
0 likes · 14 min read


21CTOOct 11, 2015 · Frontend Development
This article demystifies JavaScript closures by explaining when they are created, how the scope chain and lexical environments operate, why closures persist in memory, and how nested functions and the garbage collector interact, illustrated with clear code examples and diagrams.
closurefunctionsmemory management
0 likes · 16 min read
