this
函数预编译过程 this ——> window
全局作用域里 this ——>window
call / apply /bind 可以改变函数运行时this指向
obj.func( ); func( )里面的this指向obj
arguments
arguments.callee //找到函数的引用 就是函数的名字
func.caller
call 、 apply 和bind 改变this指向
改变this指向
call
、bind
和apply
的区别是传参列表不同
call 、bind
需要把实参按照形参的个数传进去
apply
需要传一个arguments
(实参列表)
bind
会返回一个新的函数,需要调用才能执行
test(参数1,参数2 )
--> test.call(指向谁,参数1,参数2 );
test(参数1,参数2 )
--> test.apply(指向谁,[参数1,参数2]);
test(参数1,参数2 )
--> test.bind(指向谁,参数1,参数2 )();
function Person(name, age, sex) {
this.name = name;
this.age = age;
this.sex = sex;
}
function Student(name, age, sex, tel, grade) {
//var this ={name: '',age='',sex=''}
Person.call(this, name, age, sex);
this.tel = tel;
this.grade = grade;
}