-
Notifications
You must be signed in to change notification settings - Fork 0
/
modules.js
47 lines (42 loc) · 928 Bytes
/
modules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function notSoUsefulFunction(){
var someArray = [1,2,3,4,5];
var something = "something something";
function doSomething(){
console.log(something);
}
function doSomethingElse(){
console.log(someArray);
}
}
x = notSoUsefulFunction();
function coolModule(){
var something = 'something something';
var counter = 0;
function doSomething(){
console.log(something);
}
function incrementCounter(){
counter++;
console.log(counter);
}
return {
doSomething: doSomething,
incrementCounter: incrementCounter
};
}
var more = coolModule();
more.doSomething();
more.incrementCounter();
var notModifiedByPreviousFunction = coolModule();
notModifiedByPreviousFunction.incrementCounter();
var singletonCounter = (function singleton(){
var counter=0;
function incrementCounter(){
counter++;
console.log(counter);
}
return {
incrementCounter: incrementCounter
}
})();
singletonCounter.incrementCounter();