this
1.函数预编译过程,this指向window
2.全局作用域里面this指向window
3.call/apply可以改变函数运行时this指向
4.obj.func(); func()里面的this指向obj
function test(c){
//var this = Object.create(test.prototype)或者{ __proto__ : test.prototype}
var a = 123;
function b(){}
}
AO:{
arguments:[1],
this:window,
c:1,
a:undefined,
b:function(){}
}
test(1);
new test(); //new的时候,会在函数第一行隐式执行加粗的那一行,那么加粗这一行的this会将原来的指向window的this替换掉
function test(){
console.log(this) //window
}
test();
consle.log(this) //window
var obj = {
a: function(){
console.log(this) //obj
},
name:'xx'
}
obj.a();
var name = "222";
var a = {
name : "111",
say : function(){
console.info(this.name);
}
}
var fun = a.say;
fun()
a.say()
var b = {
name:"333",
say:function(fun){
fun();
}
}
b.say(a.say)
b.say = a.say
b.say()