js里的prototype使用示例


复制代码 代码如下:

<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上
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3