The binding rule to which this points

1. Default binding rule: console.log(this === window); Implicit binding rules: the caller refers to the caller (implicit loss, parameter assignment), and the parent function can change the this of the child function to refer to 3. Show binding: call/apply/bind 4.new binding

This in the arrow function

The arrow function does not have this. Its this pointer is determined by its scope. The binding rules for this pointer are invalid

The priority to which this points

New Binding > Show Binding > Implicit Binding > Default binding

New Binding > shows an example of binding

function foo(b) { this.a = b; }

    var obj1 = {};
    var bar = foo.bind(obj1);
    bar(2);

    console.log(obj1.a); / / 2
    var baz = new bar(3);
    console.log(obj1.a); // 2 This already refers to a new object, and the reference to this object is given to Baz. The reference baz gets is not the same as the reference obj1 getsSo the value of obj1.a does not change and the value of bazconsole.log(baz.a); / / 3
Copy the code