被忽略的this和更安全的this用法
被忽略的this
function foo(){
console.log( this.a );
}
var a = 2;
foo.call( null ); //2function foo(a,b){
console.log("a:"+a,",b:"+b;
}
//将数组“展开”成参数
foo.apply( null ,[2,3]);//a:2,b:3
//使用bind(..)进行柯里化
let bar = foo.bind( null,2 );
bar( 3 ); //a:2,b:3更安全的this
间接引用
Last updated