| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>071 modern JavaScript</title>
- <style>
- body { background: #ffffff; color: #202020; font-family: sans-serif;
- margin: 12px; font-size: 18px; }
- #list li { margin: 2px 0; }
- #result { background: #ffc8c8; color: #000000; padding: 8px;
- margin-top: 12px; }
- </style>
- </head>
- <body>
- <h1>071 — modern JavaScript</h1>
- <p>ES2015+ syntax and built-ins drive the DOM: classes, arrow functions,
- template literals, destructuring, spread, Map/Set, optional chaining,
- async/await with timers and Promise jobs.</p>
- <ul id="list"></ul>
- <div id="result">checking...</div>
- <script>
- 'use strict';
- const apps = [
- { id: 'a', title: 'Alpha', tags: ['chat'] },
- { id: 'b', title: 'Beta', tags: ['blog', 'chat'] },
- { id: 'c', title: 'Gamma' },
- ];
- class Store {
- #items;
- constructor(items) { this.#items = [...items]; }
- byTag(tag) { return this.#items.filter(a => a.tags?.includes(tag) ?? false); }
- get size() { return this.#items.length; }
- }
- const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
- async function main() {
- const store = new Store(apps);
- const list = document.getElementById('list');
- list.innerHTML = apps.map(({ id, title }) => `<li data-id="${id}">${title}</li>`).join('');
- const seen = new Set();
- for (const li of list.querySelectorAll('li')) seen.add(li.dataset.id);
- await sleep(50);
- const counts = new Map([['chat', store.byTag('chat').length]]);
- let clicked = '';
- list.addEventListener('click', e => { clicked = e.target.textContent; });
- list.querySelector('li[data-id="b"]').click();
- const { size } = store;
- const ok = seen.size === 3 && counts.get('chat') === 2 && size === 3 &&
- clicked === 'Beta' && Object.entries({ x: 1 }).flat().join('') === 'x1';
- const r = document.getElementById('result');
- r.style.background = ok ? '#c8f0c8' : '#ffc8c8';
- r.textContent = `${ok ? 'MODERN-OK' : 'MODERN-FAIL'} seen=${seen.size} chat=${counts.get('chat')} size=${size} clicked=${clicked}`;
- }
- main().catch(e => { document.getElementById('result').textContent = 'MODERN-FAIL ' + e; });
- </script>
- </body>
- </html>
|