• Arrow function
  1. The this inside the arrow function is determined by the outer scope
  2. The default this binding rule does not apply to arrow functions
  3. The arrow function doesn’t have this in it. This is all found from the parent scope
  • Execute function immediately

Immediately Invoked Function Expression

function a () {} // Function declaration
var fn = function () {} // Function expression

// The recommended way to execute the function immediately; (function () {
  console.log(2)
})() / / 2

// The semicolon is best
Copy the code

role

  1. You can create a scope that has nothing to do with the outside world
  2. Automatic destruction after execution
  3. Application of modules (enclosing scope, throwing interfaces). Throw property methods to the outside, and hold properties and methods on the window