Open kujian opened 5 years ago
刚好之前写过两篇文章,看完可以比较好的回答这个面试题 面试官问:能否模拟实现JS的bind方法 面试官问:能否模拟实现JS的call和apply方法
function fun(name,age){
console.log(name,age);
console.log(this)
}
let obj = {name:'jj',age:18};
fun('zz',12); // this指向window
fun.call(obj,'jj',18); //this指向obj
fun.apply(obj,['jj',18]); //this指向obj
fun.bind(obj)('jj',18); //this指向obj
@zxjzx call
和apply
用法写反了~
@zxjzx
call
和apply
用法写反了~
thanks