The main idea of clouser is a nested function which is a function inside a function useing only parameters and variables but that uses a lot of memory, but it's a way of using the local scope of the main function in a way that cannot be accessed outside of that function and it is very useful.
But OOP is a more optimal way to use memory and by storing values in attributes inside an object and writing functions outside the main function and altering and adding values without wasting memory.
how would you define closures for a 10 year old?
Well clouser is like having a box of candy that is in public everybody can access it but you want to make it for you.
So you take it from the public to your house so you can access it with your family it's like neting it from the public.
but the bad point is that you use a lot of energy to get to the box of candy to get a piece.
so what will you do.
You use Object Oriented Programing (OOP).
you use OOP to reduce the energy lost in using the clouser methods so you stor the candy inside a place (object) and you can access it whitout losing energy anytime you want, you can add to it when ever you want.
Sofian Saleh
No comments:
Post a Comment