Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 690839c

Browse files
committedJul 27, 2018
Use template literals and const instead of var
1 parent 33868a3 commit 690839c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed
 

‎word-count-web-component/main.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,30 @@ class WordCount extends HTMLParagraphElement {
55
super();
66

77
// count words in element's parent element
8-
var wcParent = this.parentNode;
8+
const wcParent = this.parentNode;
99

1010
function countWords(node){
11-
var text = node.innerText || node.textContent
11+
const text = node.innerText || node.textContent;
1212
return text.split(/\s+/g).length;
1313
}
1414

15-
var count = 'Words: ' + countWords(wcParent);
15+
const count = `Words: ${countWords(wcParent)}`;
1616

1717
// Create a shadow root
18-
var shadow = this.attachShadow({mode: 'open'});
18+
const shadow = this.attachShadow({mode: 'open'});
1919

2020
// Create text node and add word count to it
21-
var text = document.createElement('span');
21+
const text = document.createElement('span');
2222
text.textContent = count;
2323

2424
// Append it to the shadow root
2525
shadow.appendChild(text);
2626

27-
2827
// Update count when element content changes
2928
setInterval(function() {
30-
var count = 'Words: ' + countWords(wcParent);
29+
const count = `Words: ${countWords(wcParent)}`;
3130
text.textContent = count;
32-
}, 200)
33-
31+
}, 200);
3432
}
3533
}
3634

0 commit comments

Comments
 (0)