JavaScript Prototype

 1 function Obj () {
 2     }
 3 Obj.a=0;
 4 Obj.fn=function(){
 5 }
 6 console.log(Obj.a);    //0
 7 console.log(typeof Obj.fn);//function
 8 var o=new Obj();
 9 console.log(o.a);//undefined
10 console.log(typeof o.fn);//undefined

//定义函数后,通过.为其添加的属性和函数,通过对象本身仍然可以访问得到,但是其实例却访问不到,这样的变量和函数分别称为静态变量和静态方法.

 1 function Obj(){
 2     this.a=[];
 3     this.fn=function(){
 4 
 5     }
 6 }
 7 
 8 var o1=new Obj();
 9 o1.a.push(1);
10 o1.fn={};
11 console.log(o1.a);
12 console.log(typeof o1.fn);
13 var o2=new Obj();
14 console.log(o2.a);
15 console.log(typeof o2.fn);
原文地址:https://www.cnblogs.com/lvyongbo/p/4581476.html