导航

js里的prototype

Posted on 2010-11-18 11:02  fxcser  阅读(218)  评论(0)    收藏  举报

代码
<script type="text/javascript">
function people(name){
this.name=name;
this.introduce=function(){ //对象方法
alert("my name is"+this.name);
}
}

people.run
=function(){ //类方法
alert("i can run");
}

people.prototype.jump
=function(){ //原型方法
alert("i can jump")
}

var p1=new people("vincent");
p1.introduce();
people.run();
//c#中的static
p1.jump();
</script>

 

function common(){
//.....
}
common.prototype
=new Object();

 

Object对象是common的原型,Object对象的属性和方法复制到了common上