<!--JavaScript Pseudo-protocol and inline events are different for this point - <ahref="#"onclick= "alert (this.tagname);">Click Me</a><!--Eject a - <ahref= "Javascript:alert (this.tagname);">Click Me</a><!--Eject undefined - <ahref= "Javascript:alert (This==window);">Click Me</a><!--Popup True - <inputID= "BTN"type= "button"value= "This demo"name= "button"/>
<script type= "Text/javascript" >varname = ' Somebody '; varAngela ={name:' Angela ', say:function() {alert ("I ' m" + This. Name); } }; varBTN = document.getElementById (' btn ')); //settimeout and SetInterval will also change the point of this /*Angela.say ();//i ' M Angela SetTimeout (Angela.say, n);//i ' m Somebody setinterval (Angela.say, //i ' m Somebody*/ //On ... will also change the point of this /*Angela.say ();//i ' m angela Btn.onclick = angela.say;//i ' m button*/ //anonymous function adjustment this pointSetTimeout (function() {Angela.say ();}, 1000);//I ' m AngelaSetInterval (function() {Angela.say ();}, 1000)//I ' m AngelaBtn.onclick =function() {Angela.say ();};//I ' m AngelaSetTimeout (function() {Alert ( This= = window); }, 1000);//trueBtn.onclick =function() {Alert ( This= = BTN); }//true //Call and apply adjust the point of thisAngela.say.call (BTN);//I ' m buttonSetTimeout (function() {Angela.say.call (BTN);}, 1000);//I ' m buttonSetTimeout (function() {angela.say.apply (BTN);}, 1000);//I ' m buttonBtn.onclick =function() {angela.say.apply (BTN);}//I ' m button //saves the object that this is pointing to a variable varname = ' Migo '; varMydemo ={name:' Angela ', say:function() {alert ("I ' m" + This. Name); }, Init:function () { varthat = This; document.getElementById (' btn '). onclick =function() {That.say ();//I ' m Angela This. Say ();//Here's an error This.say is not function } } }; </script>
Some of the quirks of this in JavaScript