Closures in JavaScript: Practical Examples

preview_player
Показать описание
When I learning how to code, I'd heard about closures but didn't really understand why people used them, what they were useful for, and how I'd write one. I'd often come across a makeAdder function that was used to expain closures in JavaScript and, while it kind of made sense, it didn't really highlight how I could implement them in real-life code. I'd heard things about scope trees and how it plays a part in closures but that didn't help me to understand any further.

This video aims to bridge that gap between knowing what a closure is, and how you can actually start using them in your JavaScript code today. There are two practical examples included. The first demonstrates about how you can use closures to create private values. The second demonstrates how you can create functions that are able to store values 'in memory' and continue to use those values way after a function has been executed. Hopefully this video will take your programming skills to the next level.
Рекомендации по теме
Комментарии
Автор

real question. why would you use the factory pattern instead of a class

bandr-dev
Автор

The Arsenal example was genial hahaha, great explanation!

jonathanedsilva
Автор

Came here to get closure on closures, left here with that and an Arsenal burn. Cound't be more happy! 😅

nick.h
Автор

This seems to be the classic JS interview question.
A lot of JavaScript programming seems to consist of using workarounds to replicate functionality that other languages have built in to them.
The language is evolving, albeit painfully slowly, to do what people have been trying to force it to do for years.

cawsha
Автор

I like the way you explain the Factory Functions, could you make more videos about other design patterns?

manusi
Автор

Why did you use return { } _(using curly braces)_ in the first example and not return( ) _(using parentheses)_ ?

robinr
Автор

Can you do closures with more than one inner function? Or have an outer, middle, and inner function?

BKofficer
Автор

In simple words it is a getter of inner function state?

Muhammad-isi
Автор

I've heard a rumour that at least one person on the planet understands what JS symbols are for. If you happen to be that person how about a video?

cawsha