首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

prototype兑现继承

2012-10-28 
prototype实现继承??http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd??html?xmlnshttp://www.w3

prototype实现继承

    ??"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">??
  1. <html?xmlns="http://www.w3.org/1999/xhtml">??
  2. <head>??
  3. <title>JavaScript?Inheritance?via?Prototype</title>??
  4. ??
  5. <script?type="text/javascript"?src="inheritanceViaPrototype.js"></script>??
  6. ??
  7. <script?type="text/javaScript">??
  8. ??
  9. function?describe(vehicle)?{ ??
  10. ????var?description?=?""; ??
  11. ????descriptiondescription?=?description?+?"Number?of?wheels:?"?+?vehicle.wheelCount; ??
  12. ????descriptiondescription?=?description?+?"\n\nCurb?Weight:?"?+?vehicle.curbWeightInPounds; ??
  13. ????descriptiondescription?=?description?+?"\n\nRefueling?Method:?"?+?vehicle.refuel(); ??
  14. ????descriptiondescription?=?description?+?"\n\nMain?Tasks:?"?+?vehicle.mainTasks(); ??
  15. ????alert(description); ??
  16. } ??
  17. ??
  18. function?createVehicle()?{ ??
  19. ????var?vehicle?=?new?Vehicle(); ??
  20. ????describe(vehicle); ??
  21. } ??
  22. ??
  23. function?createSportsCar()?{ ??
  24. ????var?sportsCar?=?new?SportsCar(); ??
  25. ????describe(sportsCar); ??
  26. } ??
  27. ??
  28. function?createCementTruck()?{ ??
  29. ????var?cementTruck?=?new?CementTruck(); ??
  30. ????describe(cementTruck); ??
  31. } ??
  32. </script>??
  33. </head>??
  34. ??
  35. <body>??
  36. ??<h1>Examples?of?JavaScript?Inheritance?via?the?Prototype?Method</h1>??
  37. ? ??
  38. ??<br/><br/>??
  39. ??<button?onclick="createVehicle();">Create?an?instance?of?Vehicle</button>??
  40. ? ??
  41. ??<br/><br/>??
  42. ??<button?onclick="createSportsCar();">Create?an?instance?of?SportsCar</button>??
  43. ? ??
  44. ??<br/><br/>??
  45. ??<button?onclick="createCementTruck();">Create?an?instance?of?CementTruck</button>??
  46. ??
  47. </body>??
  48. </html>??
  49. ??

热点排行