Math.random().toString(36).slice(2)
Date.now()
crypto.randomUUID()
(docs)const digitValues = new Uint8Array(16);
crypto.getRandomValues(digitValues);
const randomHash = hexValues = [...digitValues]
.map(value => value.toString(16).padStart(2, '0'))
.join('');
export const sum = (a, b) => a + b;
export const diff = (a, b) => a - b;
export const multiply = (a, b) => a * b;
export const divide = (a, b) => a / b;
export * as Mod1 from './mod1.js';
export * as Mod2 from './mod2.js';
import * as M from './module.js';
console.log(M.Mod1.sum(1, 2)); // 3
console.log(M.Mod2.multiply(5, 3)); // 15
/**
* @param {MouseEvent} event
*/
function onButtonDown(event) {
alert(event);
}
addEventListener
её контекст выполнения потерян, вот типизация и отсутствует. const unwrap = (element) => {
element.replaceWith(...element.children);
};
unwrap(document.querySelector('.div'));
<button>привет</button>
const button = document.querySelector('click', (event) => {
event.preventDefault();
button.textContent = 'пока';
}, { once: true });
main.js
, т. к. gsap
и ScrollTrigger
Вы подключили в него. const links = [...document.querySelectorAll('#filter_frm table')].reduce((acc, table) => {
table.querySelectorAll('tr > td:last-child > a').forEach((link) => {
if (link.textContent.includes('300 бр.')) { // /300\s+бр\./i.test(link.textContent)
acc.push(link.href);
}
});
return acc;
}, []);
console.log(links);
fetch('https://www.kartoteka.ru/')
.then((response) => response.arrayBuffer())
.then((buffer) => {
let html = new TextDecoder('windows-1251').decode(buffer);
let doc = new DOMParser().parseFromString(html, 'text/html');
let b = doc.querySelectorAll(".news_item .image_block_no_image p")[0].innerHTML;
console.log(b);
});
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
const lineWidth = 60;
const radius = 200;
[canvas.width, canvas.height] = [radius * 2, radius * 2];
context.beginPath();
context.arc(radius, radius, radius - lineWidth / 2, 0, Math.PI * 2);
context.closePath();
context.lineWidth = lineWidth;
context.stroke();
document.body.append(canvas);
counter.js
. Хотите каждый раз новый контекст - делайте мини-фабрику (функцию высшего порядка):function createCounter() {
let counter = 0;
function increment() {
counter++;
console.log(counter);
}
function decrement() {
counter--;
console.log(counter);
}
return {
get value() {
return counter;
},
increment,
decrement
};
}
class App {
constructor() {
this.counter = createCounter();
this.subCounter = createCounter();
}
increment() {
this.counter.increment();
}
subIncrement() {
this.subCounter.increment();
}
}