1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <title></title>6 <Scripttype= "Text/javascript">7 8 /*9 * The parser passes an implicit argument to the inside of the function each time the function is called.Ten * This implied argument is that This,this is pointing to an object, One * This object we call the context object for function execution A * - * Depending on how the function is called, this will point to a different object - * 1. When called as a function, this is always the window the * 2. When called in the form of a method, this is the object that invokes the method - */ - - + functionFun () { - Console.log ( This);//[Object Window] + } A at Fun (); - - //----------------------------------------------------------------------------------- - - functionfun2 () { - Console.log ( This); in Console.log ( This. Name);//Monkey King - } to + - //Create an Object the varobj= { * Name:"Monkey King", $ sayname:fun2Panax Notoginseng }; - the Console.log (Obj.sayname==fun2);//true + A //the same function is called, but the result is different, depending on how the function is called, this will point to a different object the obj.sayname ();//[Object Object] + - fun2 ();//[Object Window] $ $ - - </Script> the </Head> - <Body>Wuyi </Body> the </HTML>
JS Basic _this