JavaScriptプロトタイプ


window.onload = function(){   
 2        /**//*  
 3                               instanceof   (      )   (prototype)  
 4                            [    prototype chian]  
 5                   ,             ,             
 6          
 7          
 8            JavaScript ,"      ,      。"  
 9           Function Object       。  
10           Function       Function   ,Function.prototype     Object     
11           Object        Function   ,Object.prototype            
12          
13            spiderMonkey   ,        __proto__       
14          
15          
16          
17                           ,     ,     ,   ,        .  
18             
19        *  prototype          
20        *  __proto__          
21        *  instanceof         
22             
23        */   
24        Function.prototype.hi = function(){alert('hi Function');}   
25        Object.prototype.hi = function(){alert('hi Object');}   
26           
27        var a = function(){   
28            this.txt = 'a';   
29        };   
30        a.prototype = {   
31            say:function(){alert('a');}   
32        };   
33           
34        alert(a instanceof Function);//a Function   ;   
35        alert(a.__proto__ === Function.prototype);   
36        //a       Function   ;   
37        //a.__proto__    Function   
38        //Function.prototype     Function   
39           
40        alert(Function instanceof Object);   
41        //Function Object   ;   
42           
43        alert(Function.__proto__ === Function.prototype);   
44        //Function       Function   ;   
45           
46        alert(Function.prototype.__proto__ === Object.prototype);   
47        //Function          Object      
48           
49        alert(Object.__proto__ === Function.prototype);   
50        //Object       Function   ;   
51        alert(Object.prototype.__proto__);   
52        //Object            ,        ,      null;   
53           
54           
55        alert(a.prototype instanceof Object);   
56        //a            
57        alert(a.prototype.__proto__ === Object.prototype);   
58        //a         Object      
59    };