Skip to content

Instantly share code, notes, and snippets.

@qwertie
Created August 7, 2018 19:19
Show Gist options
  • Save qwertie/808f63e296d260c58187a993c86074ca to your computer and use it in GitHub Desktop.
Save qwertie/808f63e296d260c58187a993c86074ca to your computer and use it in GitHub Desktop.
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