1、var x=12;
function test(){
console.log(this.x)
}
test() //主体是window
2、var x=12;
function test(){
console.log(this.x)
}
var obj={
x:45,
ss:test
console.log(this.x)
}
}
obj.ss() //45
ss的主体是 obj,
3、var x=12;
function test(){
console.log(this.x)
}
var obj={
x:45,
ss:function(){
console.log(this) //obj
test() //12
}
}
obj.ss()
4、 var val=1;
var obj={
val:2,
dbl:function(){
var val=45;
console.log(this) //window
this.val*=2
console.log(val) //45
console.log(this.val) //2
}
}
var ss=obj.dbl
ss()