March 2018
Beginner to intermediate
458 pages
10h 34m
English
Closure is a feature which allows us to access a variable which is not in the scope of the current module. It is a way of implementing lexically scoped named binding, for example:
int add = x=> y=> x+yint addTen = add(10)addTen(5) // this will return 15
In this example, the add() function is internally called by the addTen() function. In an ideal world, the variables x and y should not be accessible when the add() function finishes its execution, but when we are calling the function addTen(), it returns 15. So, the state of the function add() is saved though code execution is finished, otherwise there is no way of knowing the add(10) value, where x = 10. We are able to find the value of x because of lexical scoping and this is called ...
Read now
Unlock full access