//1.
var x=0,
y=1;
function fn(y){
y+=2;
fn=function(x){
x+=3;
console.log(x+y);
};
console.log(x+y);
}
fn(4);
fn(5);
console.log(x+y);
//2.
var x = 2;
var obj = {
x: 3,
fn: function (x) {
this.x += --x;
console.log(x);
}
};
var fn = obj.fn;
obj.fn(4);
fn(5);
console.log(x, obj.x);
//3.
var x = 3,
obj = { x: 2 };
obj.fn = (function () {
x++;
this.x += x;
return function (y) {
x++;
y += x;
this.x += y;
console.log(x);
}
})();
var fn = obj.fn;
obj.fn(1);
fn(4);
console.log(x, obj.x)
//4.
//选项卡
//5.
let y = {
n: 10,
fn: (function (x) {
console.log(x);
return function () {
console.log(this.n + x);
}
})(y.n) //=>Uncaught ReferenceError: Cannot access 'y' before initialization
};
y.fn();
//6.
//this问题总结