js構造函數內存在的閉包

function Func(x) {
this.x = x;
this.print=function() {
console.info(this.x);
(function (){
console.info(x);
})();
}
}
var a = new Func(30);
console.dir(a);
a.age = 300;
console.dir(a.print());//300,30
//存在於構造函數內的閉包 age:30 發生了閉包
//this.print 內存在閉包,閉包發生在構造new的時候,函數構造後內存銷燬了,可是屬性存在了.閉包

相關文章
相關標籤/搜索