A Pen by Alan Moore on CodePen.
-
-
Save kahunamoore/637c89bf07b4fdac2055f7a4d9223488 to your computer and use it in GitHub Desktop.
Classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="test">Stuff | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shape { | |
constructor(x_in, y_in) { | |
this.name = "Shape"; | |
this.x = x_in; | |
this.y = y_in; | |
} | |
print() { | |
console.log(this.name + " is at x = " + this.x + " y = " + this.y); | |
} | |
} | |
class Rectangle extends Shape { | |
constructor(x, y, width, height) { | |
super(x, y); | |
this.name = "Rectangle"; | |
this.width = width; | |
this.height = height; | |
} | |
print() { | |
super.print(); | |
console.log(this.name + " has width = " + this.width + " height = " + this.height); | |
} | |
} | |
class Square extends Rectangle { | |
constructor(x, y, sideLength) { | |
super(x,y, sideLength, sideLength); | |
this.name = "Square"; | |
} | |
} | |
// var myShape = new Shape(1, 1); | |
var myShape2 = new Rectangle(1, 1, 100, 100); | |
// myShape.print(); | |
myShape2.print(); | |
var someObj = new Square(2, 2, 50); | |
myShapes = [myShape2, someObj]; | |
for( var index = 0; index < myShapes.length; index++) { | |
var shape = myShapes[index]; | |
shape.print(); | |
} | |
var myElement = $("#test"); | |
console.log(myElement); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment