js 闭包
时间:2021-05-24 10:11:16
收藏:0
阅读:0
通过闭包封装私有变量
function a() { //函数外访问不到 var s = 3; //使外部能够获得s变量的值 this.f = function () { return s } //改变s的值 this.add=function(){ s++ } } var t = new a() t.add() console.log(t.f())
评论(0)