首页 > 语言 > JavaScript > 正文

js里的prototype使用示例

2024-05-06 14:26:34
字体:
来源:转载
供稿:网友
代码如下:
<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上
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选