JavaScript Strict Mode About THIS

When many people are learning or using JavaScript, they have been distorted by this THIS in JavaScript, then this article will come to organize and summarize it. Several points of this point in strict mode.

in strict mode, in the global scope, THIS points to the Window object

“use strict”; console.log (“strict mode”); console.log (“THIS in a global scope”); console.log (“this.document === Document “, this.document === Document); console.log (” this === window “, this === WINDOW); this.a = 9804; console.log (‘this.a == = window.a === ‘, window.a);
Second, in the global scope THIS
in strict mode, this function is equal to undefined


“USE STRICT “; console.log (” strict mode “); console.log (‘” of this “in the global scope in the global scope”; function f1 () {console.log (this);} Function F2 () {Function F3 ( ) {Console.log} f3 ();} F1 (); f2 ();

Third, object THIS
  in strict mode, the THIS in the function of the object points to the object instance of the call function  

JavaScript严格模式下关于this的几种指向详解 “Use strict”; console.log (“strict mode”); console.log (“this” in the object “); var o = new object (); OA = ‘o.a’ ; {Return this.a;} console.log (O.F5 ());


  in strict mode, the THIS in the constructor points to the object instance created by the constructor.  
“Use Strict”; console.log (“strict mode”); console.log (“this” in the constructor “); function constru () {this.a = ‘constru.a’; this.f2 = function () {console.log (this.b); return this.a;}} var O2 = new constructu (); o2.b = ‘O2. B ‘; console.log (O2.f2 ());



in the event handler, in the event processing function, the THIS points to the target object of the trigger event.

“Use Strict”; Function Blue_it (E) {if (this === E.TARGET) {this.Style.BackgroundColor = “# 00F” }}} var elements = document.getlements = Document.Gtelements = Document (‘*’); for (var i = 0; i
   6, in the inline event processing function THIS 
In stringent mode, there are two cases in the inline event processing function:


Inline event processing 1

 Remnant  <elements.length ; i++){
 elements[i].onclick = blue_it;


Extension Data

JavaScript strict mode HTTPS: //
  The above is the full content of this article, I hope this article will bring a certain help to everyone's learning or work. If you have any questions, you can leave a message, thank you for your support of Tumi Cloud. 
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment