diff --git a/readme.md b/readme.md index 7bda73d..03ed7d6 100644 --- a/readme.md +++ b/readme.md @@ -145,6 +145,7 @@ const add2 = curriedSum(2) // (b) => 2 + b add2(10) // 12 ``` + ##Closure A very simplistic definition - A closure is a way of accessing a variable outside its scope. @@ -167,13 +168,11 @@ function getTicker () { tickTock(); //returns 1 tickTock(); //returns 2 ``` -The function getTimer() returns a function(internally called ticker), lets call it tickTock. +The function getTimer() returns a function(internally called ticker), lets store it in a variabke called tickTock. Ideally, when the getTimer finishes execution, its scope, with local variable tick should also not be accessible. But, it returns 1, 2, 3.. on calling tickTock(). This simply means that, somewhere it keeps a track of the variable tick. -Lexical scoping is the reason why it is able to find the value of tick, the private variable of the parent which has finished executing. This value is called a closure. The stack along with the lexical scope of the function is stored and upon re-execution same stack is restored. - - +Lexical scoping is the reason why it is able to find the value of tick - the private variable of the parent which has finished executing. This value is called a Closure. The stack along with the lexical scope of the function is stored and upon re-execution same stack is restored. ## Auto Currying Transforming a function that takes multiple arguments into one that if given less than its correct number of arguments returns a function that takes the rest. When the function gets the correct number of arguments it is then evaluated.