Skip to content

Commit a04348e

Browse files
committed
Initial commit
1 parent 5832e69 commit a04348e

File tree

4 files changed

+450
-0
lines changed

4 files changed

+450
-0
lines changed

package-lock.json

Lines changed: 324 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "closures",
3+
"version": "1.0.0",
4+
"description": "Closures explained",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "node -r @std/esm source/test.js",
8+
"watch": "watch 'clear && npm run -s test' source"
9+
},
10+
"author": "Eric Elliott",
11+
"license": "MIT",
12+
"devDependencies": {
13+
"riteway": "2.0.3",
14+
"watch": "1.0.2"
15+
},
16+
"@std/esm": "cjs",
17+
"dependencies": {
18+
"@std/esm": "0.19.7"
19+
}
20+
}

source/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// What is a closure?
2+
3+
/*
4+
A function bundled with its lexical environment.
5+
*/
6+
7+
8+
/*
9+
Data privacy
10+
11+
Encapsulation.
12+
Message passing. (calling methods)
13+
*/
14+
const safe = secret => ({
15+
getSecret: () => secret
16+
});
17+
18+
19+
const fun = secret => () => secret;
20+
21+
// curried function
22+
const add2 = a => b => a + b;
23+
24+
// partial applications of add2
25+
const inc = add2(1);
26+
const inc10 = add2(10);
27+
const inc20 = add2(20);
28+
29+
export {safe, fun, add2, inc, inc10, inc20 };

0 commit comments

Comments
 (0)