Skip to content

Instantly share code, notes, and snippets.

@stonehippo
Last active April 12, 2020 22:49
Show Gist options
  • Save stonehippo/236d5c40f52ece5401b1c004cd4336de to your computer and use it in GitHub Desktop.
Save stonehippo/236d5c40f52ece5401b1c004cd4336de to your computer and use it in GitHub Desktop.
Probing the temporal dead zone (TDZ) with classes and modules in Javascript
class Base {
constructor(x, y) {
this.x = x
this.y = y
}
get point() {
return {x: this.x, y: this.y}
}
}
export { Base }
import { Base } from './Base.js'
class Circle extends Base {
constructor(x, y, radius) {
const dumb = document.createElement('div')
super(x, y)
this.radius = radius
}
get area() {
return Math.PI * Math.pow(this.radius, 2)
}
}
export { Circle }
<?DOCTYPE HTML>
<html>
<head>
<title>TDZ</title>
</head>
<body>
<p>Exploring the TDZ</p>
</body>
<script type="module">
import { Base } from './Base.js'
import { Circle } from './Circle.js'
import { Square } from './Square.js'
const abstractThing = new Base(10,10)
console.log(abstractThing.point)
const circle = new Circle(100, 20, 10)
console.log(circle.point, circle.area)
const square = new Square(50, 50, 20)
console.log(square)
</script>
</html>
import { Base } from "./Base.js"
class Rectangle extends Base {
constructor(x, y, length, width) {
super(x, y)
this.length = length
this.width = width
}
get area() {
return this.length * this.width
}
}
export { Rectangle }
import { Rectangle } from './Rectangle.js'
class Square extends Rectangle {
constructor(x, y, length) {
super(x, y, length, length)
}
}
export { Square }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment