Last active
April 12, 2020 22:49
-
-
Save stonehippo/236d5c40f52ece5401b1c004cd4336de to your computer and use it in GitHub Desktop.
Probing the temporal dead zone (TDZ) with classes and modules in Javascript
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 Base { | |
constructor(x, y) { | |
this.x = x | |
this.y = y | |
} | |
get point() { | |
return {x: this.x, y: this.y} | |
} | |
} | |
export { Base } |
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
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 } |
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
<?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> |
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
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
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 } |
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
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