We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c395012 commit 430d4d3Copy full SHA for 430d4d3
1 file changed
function-patterns/returning-functions.html
@@ -20,10 +20,15 @@
20
var my = setup(); // alerts 1
21
my(); // alerts 2
22
23
- var setup = function (count) {
+
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 () {
29
var count = 0;
30
return function () {
- return (count += 1);
31
+ return ++count;
32
};
33
34
// usage
@@ -33,8 +38,7 @@
38
//next(); // returns 3
39
35
40
// reference
36
- // http://www.jspatterns.com/
37
- // http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate
41
+ // http://www.jspatterns.com/returning-functions/
42
</script>
43
</body>
44
</html>
0 commit comments