1.创建对象
<script type="text/javascript"> function Flower(name,addre) { this.name=name; this.addre=addre; this.showName=myName; } function myName() { alert(this.name); } var fi=new Flower("牡丹","洛阳"); fi.showName(); </script>
<script type="text/javascript"> var fowlor={ name:"牡丹", showName:function () { alert(fowlor.name); } }; fowlor.showName(); </script>
<script type="text/javascript"> function Flower() { } Flower.prototype.name="牡丹花"; Flower.prototype.addre="洛阳"; Flower.prototype.showName=function () { alert(this.name) } var flag=Flower.prototype.constructor==Flower; alert(flag); var flower1=new Flower(); flower1.showName(); </script>
<script type="text/javascript"> function Humens() { this.foot=2; } Humens.prototype.getFoot=function () { return this.foot; } function Man() { this.hade=1; } Man.prototype=new Humens(); Man.prototype.getHead=function () { return this.head; } var man1=new Man(); alert(man1.foot); </script>
<script type="text/javascript"> function Humens() { this.sport=["baskball","baseball","pingpong"]; } function Man() { Humens.call(this); } Man.prototype=new Humens(); var man1=new Man(); man1.sport.push("tang"); alert(man1.sport); var man2=new Man(); alert(man2.sport); </script>