Skip to content

Commit 430d4d3

Browse files
committed
fixed chuanxshi#33, thanks to dirkbonhomme for the highlight
1 parent c395012 commit 430d4d3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

function-patterns/returning-functions.html

+8-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@
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
@@ -33,8 +38,7 @@
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>

0 commit comments

Comments
 (0)