Skip to content

Instantly share code, notes, and snippets.

@dgloriaweb
Last active July 23, 2018 09:24
Show Gist options
  • Save dgloriaweb/2491ad20b1680440f64e605cf03f5dff to your computer and use it in GitHub Desktop.
Save dgloriaweb/2491ad20b1680440f64e605cf03f5dff to your computer and use it in GitHub Desktop.
Javascript Demo - abstract class// source http://jsbin.com/murajar
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Javascript Demo - Polymorphism</title>
<link rel="stylesheet" type="text/css" href="css.css" />
<script type="text/javascript" src="jsC.js"></script>
</head>
<body>
<script id="jsbin-javascript">
var Shape = function(){
}
Shape.prototype.draw= function(){
return "I am a generic shape";
}
var Circle = function(){}
Circle.prototype = Object.create(Shape.prototype);
Circle.prototype.draw= function()
{
return "I am a circle";
}
var Square = function(){}
Square.prototype = Object.create(Shape.prototype);
Square.prototype.draw= function()
{
return "I am a square";
}
var Triangle = function(){}
Triangle.prototype = Object.create(Shape.prototype);
var shapes = [new Shape(), new Circle, new Square, new Triangle];
shapes.forEach(function(shape){
document.write(shape.draw()+"<br/>");
})
</script>
<script id="jsbin-source-javascript" type="text/javascript">var Shape = function(){
}
Shape.prototype.draw= function(){
return "I am a generic shape";
}
var Circle = function(){}
Circle.prototype = Object.create(Shape.prototype);
Circle.prototype.draw= function()
{
return "I am a circle";
}
var Square = function(){}
Square.prototype = Object.create(Shape.prototype);
Square.prototype.draw= function()
{
return "I am a square";
}
var Triangle = function(){}
Triangle.prototype = Object.create(Shape.prototype);
var shapes = [new Shape(), new Circle, new Square, new Triangle];
shapes.forEach(function(shape){
document.write(shape.draw()+"<br/>");
})</script></body>
</html>
var Shape = function(){
}
Shape.prototype.draw= function(){
return "I am a generic shape";
}
var Circle = function(){}
Circle.prototype = Object.create(Shape.prototype);
Circle.prototype.draw= function()
{
return "I am a circle";
}
var Square = function(){}
Square.prototype = Object.create(Shape.prototype);
Square.prototype.draw= function()
{
return "I am a square";
}
var Triangle = function(){}
Triangle.prototype = Object.create(Shape.prototype);
var shapes = [new Shape(), new Circle, new Square, new Triangle];
shapes.forEach(function(shape){
document.write(shape.draw()+"<br/>");
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment