回答編集履歴
2
throw expression の話も足す
test
CHANGED
@@ -14,3 +14,12 @@
|
|
14
14
|
logTemplate.parentElement.querySelectorAll(':scope > :nth-child(n + 100 of :not(template))')
|
15
15
|
}
|
16
16
|
</script>
|
17
|
+
```
|
18
|
+
|
19
|
+
throw expression が実装されたなら次の様に書くのではありますが……。(なのでちょっと書きづらいので要所要所ですね。
|
20
|
+
|
21
|
+
https://github.com/tc39/proposal-throw-expressions
|
22
|
+
|
23
|
+
```js
|
24
|
+
logTemplate ?? throw new Error('required id=logTemplate element.');
|
25
|
+
```
|
1
clone の仕方を修正
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
if (!logTemplate) throw new Error('required id=logTemplate element.');
|
9
9
|
addLog('hello world.');
|
10
10
|
function addLog(message) {
|
11
|
-
const row = logTemplate.content.cloneNode(true)
|
11
|
+
const row = logTemplate.content.firstElementChild.cloneNode(true);
|
12
12
|
row.innerText = `${message}`;
|
13
13
|
logTemplate.insertAdjacentElement('afterend', row);
|
14
14
|
logTemplate.parentElement.querySelectorAll(':scope > :nth-child(n + 100 of :not(template))')
|