Skip to content

Commit 83135f7

Browse files
committed
Simple JavaScript examples added
1 parent 29ba20c commit 83135f7

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
*.log
3+
.DS_Store

JavaScript/1-closure.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
function hash() {
4+
let data = {};
5+
let counter = 0;
6+
return function(key, value) {
7+
data[key] = value;
8+
counter++;
9+
console.dir({ counter });
10+
return data;
11+
};
12+
}
13+
14+
let h1 = hash();
15+
h1('name', 'Marcus');
16+
h1('city', 'Roma');
17+
let obj1 = h1('born', 121);
18+
console.dir({ obj1 });

JavaScript/2-chain.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
function hash() {
4+
let data = {};
5+
Object.defineProperty(data, 'add', {
6+
enumerable: false,
7+
value: function(key, value) {
8+
data[key] = value;
9+
return data;
10+
}
11+
});
12+
return data;
13+
}
14+
15+
console.dir(
16+
hash()
17+
.add('name', 'Marcus')
18+
.add('city', 'Roma')
19+
.add('born', 121)
20+
);

0 commit comments

Comments
 (0)