-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclockClass.js
More file actions
49 lines (37 loc) · 964 Bytes
/
clockClass.js
File metadata and controls
49 lines (37 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Clock {
constructor({template}) {
this.template = template;
};
render(){
let date = new Date();
let hours = date.getHours();
if(hours < 10) hours = '0'+hours;
let mins = date.getMinutes();
if(min < 10) mins = '0'+mins;
let secs = date.getSeconds();
if(sec < 10) sec = '0'+sec;
let output = this.template
.replace('h',hours)
.replace('m',mins)
.replace('s',secs);
console.log(output);
};
stop(){
clearInterval(this.timer);
}
start(){
this.render();
this.timer = setInterval(()=> this.render(),1000);
}
}
class ExtendedClock extends Clock {
constructor(options){
super(options);
let {precision = 1000 } = options;
this.precision = precision;
}
start() {
this.render();
this.timer = setInterval(()=>this.render(),this.precision);
}
}