Javascript Closure建議寫法

Javascript Closure建議寫法

這篇介紹jshint、eslint建議Javascript Closure的寫法。

Javascript Closure Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const Test1 = (function () {
let a = 5;

function function1() {
a += 1;
return a;
}

function function2() {
a -= 1;
return a;
}

return {
function1,
function2,
};
}());

console.log(Test1.function1());
console.log(Test1.function2());