- 利用闭包存放状态值
function addc(){var c = 0; return function(x){c+=x;return c;}}
undefined
var caddx = addc()
undefined
caddx(1)
1
caddx(1)
2
caddx(1)
3
caddx(1)
4
caddx(5)
9
function addc(){var c = 0; return function(x){c+=x;return c;}}
undefined
var caddx = addc()
undefined
caddx(1)
1
caddx(1)
2
caddx(1)
3
caddx(1)
4
caddx(5)
9