前端题

 

1.new Parent.num代码相当于new (Parent.num);new Parent().num相当于(new Parent()).num。由此看来 new的构造函数后跟括号优先级会提升

2.callapplybind方法的共同点和区别:
apply 、 call 、bind 三者都是用来改变函数的this对象的指向的
apply 、 call 、bind 三者第一个参数都是this要指向的对象,也就是想指定的上下文(函数的每次调用都会拥有一个特殊值——本次调用的上下文(context)——这就是this关键字的值。)

bind 是返回对应函数,便于稍后调用;apply 、call 则是立即调用 。
 

function eat(){
    console.log("eat");
}
function drink(){
    console.log("drink");
}
drink.call(eat); //eat



function a(x,y){
    console.log(x+y);
    this(3,2);
}
var c= function (x,y) {
    console.log(x-y)
};
a.call(c,3,2); // 5,1


function Animal(){
    this.name="animal";
    this.showName=function(){
        console.log(this.name);
    }
}
function Dog(){
    this.name="dog";
}
var animal=new Animal();
var dog=new Dog();
animal.showName.call(dog); // dog 

 

 class1.call(this,args1,args2);  
  /*或*/
  class1.apply(this,[args1,args2]);

 

3.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值