javascriptオブジェクトの属性、方法、prototypeの作用範囲分析

7725 ワード

このブログを読んで、「javascriptオブジェクトの属性、方法、prototypeの役割範囲分析」を自分で一回書きました.後で自分で使うことができます.
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
 5     <title>javascript     ,  ,prototype      </title>
 6 </head>
 7 <body>
 8     
 9 </body>
10 </html>
11 <script type="text/javascript">
12     function Obj(arg){
13 
14         /* 1 :     ,                           */
15         var a = arg;                     //                          
16         var fn=function(){};             //                          
17  
18         /* 2 */
19         this.b=arg;                      //                             (            ,                .)                    .
20         this.fn1=function(){};           //                             
21     }
22         /* 3             ,            .*/
23          Obj.c=1;                                //                          
24          Obj.fn2=function(){};                   //                          
25 
26         /* 4 */
27          Obj.prototype.d=11;                     //                           
28          Obj.prototype.fn3=function(){};         //                           
29 
30          /* 2   4                      ,           */
31 
32     console.log("Obj.a = "+Obj.a);                                   //Obj.a = undefined
33     console.log("Obj.fn = "+Obj.fn);                                 //Obj.fn = undefined
34      
35     console.log("Obj.b = "+ Obj.b);                                  //Obj.b = undefined
36     console.log("Obj.fn1 = "+ Obj.fn1);                              //Obj.fn1 = undefined
37 
38     console.log("Obj.c = "+ Obj.c);                                  //Obj.c = 1
39     console.log("Obj.fn2 = "+Obj.fn2);                               //Obj.fn2 = function (){}
40 
41     console.log("Obj.d = "+ Obj.d);                                  //Obj.d = undefined
42     console.log("Obj.fn3 = "+Obj.fn3);                               //Obj.fn3 = undefined
43     console.log("--------------------------------------");
44 
45     var A = new Obj(22);
46     console.log("A.a = "+A.a);                             //A.a = undefined
47     console.log("A.fn = " +A.fn);                          //A.fn = undefined
48 
49     console.log("A.b = "+ A.b);                            //A.b = 22
50     console.log("A.fn1 = "+A.fn1);                         //A.fn1 = function (){}
51 
52     console.log("A.c = "+A.c);                             //A.c = undefined
53     console.log("A.fn2 = "+A.fn2);                         //A.fn2 = undefined
54 
55     console.log("A.d = "+A.d);                             //A.d = 11
56     console.log("A.fn3 = "+A.fn3);                         //A.fn3 = function (){}
57 
58     /* 1,3,4       . 2                       .       this                          .   this   .*/
59 </script>