Tag:join access class on () new t javascrip array object-oriented turn
<script type= "Text/javascript" >//Prototype chain inherit function shape () {this.name= "shape"; This.showname=function () {console.log (this.name); }} function Shape_two () {this.name= ' Shape_two '} function Triangle (side,height ) {this.name= "Triangle"; This.side=side; This.height=height; This.getinfo=function () {console.log (this.side * THIS.HEIGHT/2); }} shape_two.prototype=new shape (); Triangle.prototype=new Shape_two (); Shape_two.prototype.constructor=shape_two; Triangle.prototype.constructor=triangle; var mytri= new Triangle (10,8); Console.log (Mytri.name); Mytri.getinfo (); Mytri.showname (); Console.log (Mytri.constructor); Console.log (Mytri instanceof Triangle); Console.log (Mytri instanceof shape); Console.log (Mytri instanceof Shape_two); Console.log (Mytri instanceof Array); var mytri_2=new shape_two (); Mytri_2.showname (); var mytri_3= new shape (); Console.log (Mytri_3.constructor); function Shape_pro () {shape_pro.prototype.name= ' Shape_pro '; Shape_pro.prototype.showname=function () {console.log (this.name); }} function Shape_twopro () {}; Shape_twopro.prototype=new Shape_pro (); Shape_twopro.prototype.constructor=shape_twopro; Shape_pro.prototype.name= "Shape_twopro"; function Trianglepro (side,height) {this.side=side; This.height=height; } trianglepro.prototype=new Shape_twopro (); Trianglepro.prototype.constructor=trianglepro; Trianglepro.prototype.name= "Trianglepro"; Trianglepro.prototype.getarea=function () {console.log (THIS.SIDE*THIS.HEIGHT/2); } var newmytri= newTrianglepro (12,8); Newmytri.showname (); Newmytri.getarea (); Console.time (Newmytri.getarea ()); Temporary constructor new F (); function Shape_snap () {shape_snap.prototype.name= "snap"; Shape_snap.prototype.showname=function () {console.log (this.name); }} function Shape_snaptwo () {}; var newf =function () {}; Newf.prototype=shape_snap.prototype; Shape_snaptwo.prototype=new Newf (); Shape_snaptwo.prototype.constructor=shape_snaptwo; Shape_snaptwo.prototype.name= ' Shape_snaptwo '; function Triangleshape (side,height) {this.side=side; This.height=height; } var newf =function () {}; Newf.prototype=shape_snaptwo.prototype; Triangleshape.prototype=new Newf (); Triangleshape.prototype.construcTor=triangleshape; Triangleshape.prototype.name= ' Triangleshape '; Triangleshape.prototype.getarea=function () {console.log (THIS.SIDE*THIS.HEIGHT/2); } var mytrinew=new triangleshape (10,20); Mytrinew.getarea (); var sname= new Shape_snap (); Sname.showname (); Child object Access Parent object Uber function Shape_uber () {shape_uber.prototype.name= "Shape_uber"; Shape_uber.prototype.showubername=function () {var result =[]; if (This.constructor.uber) {result[result.length] =this.constructor.uber.showubername (); } result[result.length]=this.name; Return Result.join (', '); } }; function Shape_ubertwo () {}; var newf=function () {}; Newf.prototype=shaPe_uber.prototype; Shape_ubertwo.prototype=new Newf (); Shape_ubertwo.prototype.constructor=shape_ubertwo; Shape_ubertwo.uber=shape_uber.prototype; Shape_ubertwo.prototype.name= "Shape_ubertwo"; function Shape_ubertriangle (side,height) {this.side=side; This.height=height; } var newf=function () {}; Newf.prototype=shape_ubertwo.prototype; Shape_ubertriangle.prototype=new Newf (); Shape_ubertriangle.prototype.constructor=shape_ubertriangle; Shape_ubertriangle.uber=shape_ubertwo.prototype; Shape_ubertriangle.prototype.name= ' Shape_ubertriangle '; Shape_ubertriangle.prototype.getarea=function () {console.log (THIS.SIDE*THIS.HEIGHT/2); } var mytridd= new Shape_ubertwo (); </script>
JavaScript Object-oriented prototype inheritance