11.bind-call-apply方法

2019-06-06  本文已影响0人  Fl_来看看

1.this是什么?

2.这三个方法的作用是什么?

2.1.bind方法作用
修改函数或者方法中的this为指定的对象, 并且会返回一个修改之后的新函数给我们

2.2.call方法作用

2.3.apply方法作用

 let obj = {
            name: "zs"
        }
        /*
        // function test(a, b) {
        //     console.log(a, b);
        //     console.log(this);
        // }
        // test(10, 20);
        // window.test();
        // let fn = test.bind(obj, 10, 20);
        // fn();

        // test.call(obj, 10, 20);

        // test.apply(obj, [10, 20]);
        */

        function Person() {
            this.name = "lnj";
            this.say = function () {
                console.log(this);
            }
        }
        let p = new Person();
        // p.say();
        // let fn = p.say.bind(obj);
        // fn();
        // p.say.call(obj);
        p.say.apply(obj);

学这些是为了解决
10.继承方式一

上一篇 下一篇

猜你喜欢

热点阅读