I have an abstract class “Component”
JavaScript
x
13
13
1
abstract class Component {
2
protected container: HTMLElement;
3
4
constructor(tagName: string, className: string) {
5
this.container = document.createElement(tagName);
6
this.container.className = className;
7
}
8
9
render() {
10
return this.container;
11
}
12
}
13
Other classes extend this class. Is there a way to make render()
return a this.container
, which later will be deleted from DOM, i.e. after 5 seconds?
Advertisement
Answer
Have you tried using setTimeout
?
JavaScript
1
16
16
1
abstract class Component {
2
protected container: HTMLElement;
3
4
constructor(tagName: string, className: string) {
5
this.container = document.createElement(tagName);
6
this.container.className = className;
7
}
8
9
render() {
10
setTimeout(() => {
11
this.container.remove()
12
}, 5000)
13
return this.container;
14
}
15
}
16