this 指向
// this 指向问题
function fun() {
var self = this;
self.name = name||'default';
return {
show : function(){
console.log(1, self.name)
},
setName: function (name) {
self.name = name;
return this;
}
}
}
var obj = fun()
console.log(2, obj.setName('sdf').show())
console.log(3, fun().show())
闭包
// 闭包问题
var addCount;
function s1() {
var count = 0;
function s12() {
console.log(count)
}
addCount = function() {
count++;
};
return s12
}
var result1 = s1();
var result2 = s1();
addCount();
result1();
result2();