JS中call()和apply()以及bind()的区别

    // call方法的应用
    // 调用这个函数,并且修改这个函数的指向
    function ab(){
        console.log('喝咖啡')
        console.log(this)
    }
    let o1 = {
        name:'andy'
    }
    // ab();
    ab.call();
    // 喝咖啡

    // ab.call(o1, 1, 2);


    // 父构造函数
    // this 指向父构造函数的对象实例
    function father(uname, age){
        this.uname = uname;
        this.age = age;
    }
    // 子构造函数 通过call 继承父构造函数的属性
    function son (uname, age){
        father.call(this, uname, age);
    }
    let son1 = new son('刘德华', 20)
    console.log(son1)
    // {uname: "刘德华", age: 20}

https://blog.csdn.net/qq_36772866/article/details/88093654

https://www.cnblogs.com/lmsblogs/p/11271111.html

原文地址:https://www.cnblogs.com/yizhilin/p/14431224.html