When you use function() { ... }
it changes what this
is while inside the function. You either need to bind the function to this
or use an arrow function () => { ... }
.
Using bind:
var handleClick = function() { this.close();};this.dialog.onclick = handleClick.bind(this)
Using arrow function:
this.dialog.onclick = () => { this.close();}