zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js里的prototype使用示例

JS 使用 示例 prototype
2023-06-13 09:14:25 时间
复制代码代码如下:

<scripttype="text/javascript">
functionpeople(name){
this.name=name;
this.introduce=function(){//对象方法
alert("mynameis"+this.name);
}
}

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

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

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

复制代码代码如下:

functioncommon(){
//.....
}
common.prototype=newObject();

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