File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 2020 var my = setup ( ) ; // alerts 1
2121 my ( ) ; // alerts 2
2222
23- var setup = function ( count ) {
23+
24+
25+ // Your setup function can store some private data in a closure and use that data somehow.
26+ // Here setup() creates a counter function, which gives a next ID for example. But the count variable is not exposed.
27+
28+ var setup = function ( ) {
2429 var count = 0 ;
2530 return function ( ) {
26- return ( count += 1 ) ;
31+ return ++ count ;
2732 } ;
2833 } ;
2934 // usage
3338 //next(); // returns 3
3439
3540 // reference
36- // http://www.jspatterns.com/
37- // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate
41+ // http://www.jspatterns.com/returning-functions/
3842 </ script >
3943 </ body >
4044</ html >
You can’t perform that action at this time.
0 commit comments