js里的prototype使用示例
2026-01-17 15:32:11 作者:用户投稿
复制代码 代码如下:
<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上
<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上
联络方式:
4008905355
邮箱:9196886@qq.com
Q Q:9196886
微信二维码
