js: the this pointer in the function function under normal mode and strict mode use strict in the browser environment

normal mode

Normal mode thispoints to the defaultWindow

function foo() {
    
    
  console.log(this);
}

foo(); // Window

strict mode

If strict mode is enabled use strict, thisit points toundefined

function foo() {
    
    
 "use strict";
  console.log(this);
}

foo(); // undefined

Guess you like

Origin blog.csdn.net/mouday/article/details/132128340