实现代码如下:

<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上

以上就是【js里的prototype使用示例】的全部内容了,欢迎留言评论进行交流!

赞(0) 踩(0)
发表我的评论

最新评论

  1. 暂无评论