Created
August 7, 2018 19:19
-
-
Save qwertie/808f63e296d260c58187a993c86074ca to your computer and use it in GitHub Desktop.
This file contains 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 Box { | |
constructor(width, height) { // initializer | |
this.width = width; | |
this.height = height; | |
} | |
get area() { return this.width*this.height; } // getter function | |
setSquare(side) { // normal function | |
// set the Box's width and height to side, representing a square | |
this.width = this.height = side; | |
} | |
static ZeroSize() { return new Box(0, 0); } // static (class-level) function | |
} | |
var big = new Box(1920, 1080); | |
var mini = new Box(19.2, 10.8); | |
console.log(`The big box is ${big.area/mini.area} times larger than the minibox`); | |
console.log(`The area of the zero-size box is ${Box.ZeroSize().area}.`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment