Guest User

Untitled

a guest
Jul 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>Javascript Demo - Polymorphism</title>
  7. <link rel="stylesheet" type="text/css" href="css.css" />
  8. <script type="text/javascript" src="jsC.js"></script>
  9. </head>
  10. <body>
  11. <script id="jsbin-javascript">
  12. var Shape = function(){
  13.  
  14. }
  15. Shape.prototype.draw= function(){
  16. return "I am a generic shape";
  17. }
  18. var Circle = function(){}
  19. Circle.prototype = Object.create(Shape.prototype);
  20. Circle.prototype.draw= function()
  21. {
  22. return "I am a circle";
  23. }
  24. var Square = function(){}
  25. Square.prototype = Object.create(Shape.prototype);
  26. Square.prototype.draw= function()
  27. {
  28. return "I am a square";
  29. }
  30. var Triangle = function(){}
  31. Triangle.prototype = Object.create(Shape.prototype);
  32.  
  33. var shapes = [new Shape(), new Circle, new Square, new Triangle];
  34.  
  35. shapes.forEach(function(shape){
  36. document.write(shape.draw()+"<br/>");
  37. })
  38. </script>
  39.  
  40.  
  41.  
  42. <script id="jsbin-source-javascript" type="text/javascript">var Shape = function(){
  43.  
  44. }
  45. Shape.prototype.draw= function(){
  46. return "I am a generic shape";
  47. }
  48. var Circle = function(){}
  49. Circle.prototype = Object.create(Shape.prototype);
  50. Circle.prototype.draw= function()
  51. {
  52. return "I am a circle";
  53. }
  54. var Square = function(){}
  55. Square.prototype = Object.create(Shape.prototype);
  56. Square.prototype.draw= function()
  57. {
  58. return "I am a square";
  59. }
  60. var Triangle = function(){}
  61. Triangle.prototype = Object.create(Shape.prototype);
  62.  
  63. var shapes = [new Shape(), new Circle, new Square, new Triangle];
  64.  
  65. shapes.forEach(function(shape){
  66. document.write(shape.draw()+"<br/>");
  67. })</script></body>
  68. </html>
Add Comment
Please, Sign In to add comment