[jQuery Note]jQuery JavaScript Object fundamentals extend

Let's continue the last section.

 
I want to show my idea by a comprehensive example.
 
 
<html>

     <head>

          <title>I like that</title>

          <script>

               var o1={handle:'o1'};

               var o2={handle:'o2'};

               var o3={handle:'o3'};

 

               window.handle='window';

               

               function whoAmI(){

                    return this.handle;

               }

 

               o1.functionName=whoAmI;

 

               alert(whoAmI());

 

               alert(o1.functionName());

 

               alert(whoAmI.call(o2));

 

               alert(whoAmI.apply(o3));

          <script>

     </head>

     <body>

     </body>

<html>

 

 
 
when this code is running,
 
 
'window';
'o1';
'o2';
'o3';
 
 
will show one by one.
 
The key-word 'this' points to the object who calls it.

你可能感兴趣的:(JavaScript)