One, foreword

The “use strict” directive is new in JavaScript 1.8.5 (ECMAScript5). It is not a statement, but is a literal expression that was ignored in older versions of JavaScript. The purpose of “use strict” is to specify that code should be executed under strict conditions, in which you cannot use undeclared variables.

Second, strict schema declaration

Add “use strict” to the javascript script or function header; Expression to declare.

Third, strict mode restrictions

  1. Undeclared variables are not allowed
  2. Objects or variables cannot be deleted
  3. Deleting functions is not allowed
  4. Duplicate names of variables are not allowed
  5. Escape characters are not allowed
  6. Assignment to read-only attributes is not allowed
  7. Disallow the this keyword to refer to global objects (inside functions or in Es6 classes (strict mode is turned on by default) where this refers to ‘undefined’).
function f() {
    "use strict"
    this.a = 1   // Error: this is undefined
}
Copy the code

Next: How to solve the This pointing problem in class components.