I spend half hour and number of different codes just to figure out what mistake I am doing and in the end, my mistake was that I wasn't putting semicolon after right curly brace.
You don't undestand why Closures exist... They are not meant to just be function with a $ variable... If you are calling an anonymous function multiple times then you are doing it wrong. Anonymous functions are mainly there for code you only need to run once, and the main advantage is encapsulation of the variables inside...
DrakenKin Basically with closures you have the encapsulation of functions without the disadvantages of polluting the global space with a function you will only run once. That's their ideal, and dare i say their only real utility.
Nice explanation, simple and straightforward.
you really like number 5, thank you for tutorials
I spend half hour and number of different codes just to figure out what mistake I am doing and in the end, my mistake was that I wasn't putting semicolon after right curly brace.
HAAHA! Me too... sucks.,
You don't undestand why Closures exist... They are not meant to just be function with a $ variable... If you are calling an anonymous function multiple times then you are doing it wrong. Anonymous functions are mainly there for code you only need to run once, and the main advantage is encapsulation of the variables inside...
DrakenKin Basically with closures you have the encapsulation of functions without the disadvantages of polluting the global space with a function you will only run once. That's their ideal, and dare i say their only real utility.
thanks for this. cheers.
1 dislike? Hater...