1. const obj1 = { a: 1 };
    2. const obj2 = { a: 2 };
    3. function test() {
    4. console.log(this.a);
    5. }
    6. test(); // undefined
    7. test.bind(obj1)(); // 1
    8. test.bind(obj2)(); // 2
    9. test.bind(obj1).bind(obj2)(); // 1
    1. // 只是模拟效果,不是模拟实现bind
    2. // test.bind(obj1) => tempFun1
    3. function tempFun1() {
    4. return test.call(obj1);
    5. }
    6. tempFun1(); // 1
    7. // test.bind(obj1).bind(obj2) => tempFun2
    8. function tempFun2() {
    9. return tempFun1.call(obj2);
    10. }
    11. tempFun2(); // 1

    简而言之,func.bind(obj) 返回的新函数 boundFunc 中,func 内部的 this 指向并不依赖于 boundFuncthis,而是直接指向 obj

    事实上,后续的重复 bind 也只是在改变 boundFuncthis 指向,而不是在改变 functhis 指向。