clock
This commit is contained in:
parent
16cfa3037b
commit
cdc1693443
7 changed files with 43 additions and 63 deletions
|
@ -1,9 +1,9 @@
|
|||
class Clock {
|
||||
constructor({ template }) {
|
||||
this._template = template;
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
_render() {
|
||||
render() {
|
||||
let date = new Date();
|
||||
|
||||
let hours = date.getHours();
|
||||
|
@ -15,7 +15,7 @@ class Clock {
|
|||
let secs = date.getSeconds();
|
||||
if (secs < 10) secs = '0' + secs;
|
||||
|
||||
let output = this._template
|
||||
let output = this.template
|
||||
.replace('h', hours)
|
||||
.replace('m', mins)
|
||||
.replace('s', secs);
|
||||
|
@ -24,11 +24,11 @@ class Clock {
|
|||
}
|
||||
|
||||
stop() {
|
||||
clearInterval(this._timer);
|
||||
clearInterval(this.timer);
|
||||
}
|
||||
|
||||
start() {
|
||||
this._render();
|
||||
this._timer = setInterval(() => this._render(), 1000);
|
||||
this.render();
|
||||
this.timer = setInterval(() => this.render(), 1000);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue