- Arrow function
- The this inside the arrow function is determined by the outer scope
- The default this binding rule does not apply to arrow functions
- 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
- You can create a scope that has nothing to do with the outside world
- Automatic destruction after execution
- Application of modules (enclosing scope, throwing interfaces). Throw property methods to the outside, and hold properties and methods on the window