File tree 1 file changed +7
-9
lines changed 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -5,32 +5,30 @@ class WordCount extends HTMLParagraphElement {
5
5
super ( ) ;
6
6
7
7
// count words in element's parent element
8
- var wcParent = this . parentNode ;
8
+ const wcParent = this . parentNode ;
9
9
10
10
function countWords ( node ) {
11
- var text = node . innerText || node . textContent
11
+ const text = node . innerText || node . textContent ;
12
12
return text . split ( / \s + / g) . length ;
13
13
}
14
14
15
- var count = ' Words: ' + countWords ( wcParent ) ;
15
+ const count = ` Words: ${ countWords ( wcParent ) } ` ;
16
16
17
17
// Create a shadow root
18
- var shadow = this . attachShadow ( { mode : 'open' } ) ;
18
+ const shadow = this . attachShadow ( { mode : 'open' } ) ;
19
19
20
20
// Create text node and add word count to it
21
- var text = document . createElement ( 'span' ) ;
21
+ const text = document . createElement ( 'span' ) ;
22
22
text . textContent = count ;
23
23
24
24
// Append it to the shadow root
25
25
shadow . appendChild ( text ) ;
26
26
27
-
28
27
// Update count when element content changes
29
28
setInterval ( function ( ) {
30
- var count = ' Words: ' + countWords ( wcParent ) ;
29
+ const count = ` Words: ${ countWords ( wcParent ) } ` ;
31
30
text . textContent = count ;
32
- } , 200 )
33
-
31
+ } , 200 ) ;
34
32
}
35
33
}
36
34
You can’t perform that action at this time.
0 commit comments