JavaScript Closures
closure chenmoH, function wa' variable pagh function tlhoch scope Daq tlhap. closure ghaH function, chenmoHta'DI' scope Dung values qaw.
misvam example Daq yIlaD:
function greeting(name) {
return function() {
console.log("Hello, " + name + "!");
};
}
const greetJohn = greeting("John");
const greetMary = greeting("Mary");
greetJohn(); // Output: Hello, John!
greetMary(); // Output: Hello, Mary!
example Daq "greeting" function ghaj, closure nob, pong qaw. "greeting" Qu'DI' pong nob. closure Hoch vay' vaD nob (variables Daq).
closures Qu'DI', pong qawpu' 'ej "Hello, [Name]!" ghItlh.
closures lo'laH De' So' 'ej function-mey chu' interface Dun nob. 'ach scope variables Sovbe'DI' closures ngaj.
closures Qapla' 'ej Qagh pagh ghaj, scope yaj 'ej variables function-mey Dun lo'.