const getNested = (root, path) => path.split('.').reduce((p, c) => p != null ? p[c] : p, root);
const id = getNested(e, 'path.1.attributes.uid.textContent');
// можно немного сократить функцию извлечения вложенных значений
const getNested = (root, path) => path.split('.').reduce((p, c) => p?.[c], root);
// а можно и вообще отказаться от этой функции, смысла в ней теперь немного
const id = e?.path?.[1]?.attributes?.uid?.textContent;
function handler(e) {
console.log('hello, world!!');
this.removeEventListener(e.type, handler);
}
document.addEventListener('click', handler);
document.addEventListener('click', handler, { once: true });
const result = arr.reduce((acc, n, i) => {
if (здесь вы проверяете элемент массива на соответствие своему условию) {
let group = acc[acc.length - 1];
if (!group || group.index !== i - 1) {
group = { data: [] };
acc.push(group);
}
group.index = i;
group.data.push(n);
}
return acc;
}, []).map(n => n.data);
phone.value = phone.value.replace(/[^+0-9]/g, '').slice(0, 11);
const canvas = document.querySelector('#canvas');
const ctx = canvas.getContext('2d');
const TILE_SIDE = 32;
let pickX = 0;
let pickY = 0;
const ground = new Image();
ground.src = 'Ground.png';
const pick = new Image();
pick.src = 'Pick.png';
document.addEventListener('keydown', function(e) {
switch (e.keyCode) {
case 87: pickY -= TILE_SIDE; break;
case 65: pickX -= TILE_SIDE; break;
case 83: pickY += TILE_SIDE; break;
case 68: pickX += TILE_SIDE; break;
default: return;
}
draw();
});
function draw() {
for (let x = 0; x < canvas.width; x += TILE_SIDE) {
for (let y = 0; y < canvas.height; y += TILE_SIDE) {
ctx.drawImage(ground, x, y);
}
}
ctx.drawImage(pick, pickX, pickY);
}
draw();
<div class="accordionFaq"></div>
const playersOptions = [
{ source: '...' },
{ source: '...' },
...
];
$('.accordionFaq').html(playersOptions.map((n, i) => `
<div class="accordionFaq-item">
<div class="accordionFaq-head js-accordionFaq-head">
Video #${i}
</div>
<div class="accordionFaq-body">
<div id="player${i}"></div>
</div>
</div>
`).join('')).on('click', '.accordionFaq-head', function(e) {
const index = $(this).closest('.accordionFaq-item').index();
$('.accordionFaq-item', e.delegateTarget).each(function(i) {
const
$this = $(this),
isClicked = i === index,
active = isClicked && !$this.hasClass('active');
$(this)
.toggleClass('active', active)
.find('.accordionFaq-body')
[isClicked ? 'slideToggle' : 'slideUp']();
playersOptions[i].player[active ? 'play' : 'pause']();
});
});
playersOptions.forEach((n, i) => {
n.player = new Clappr.Player({
source: n.source,
parentId: `#player${i}`,
});
});
const getNum = () => new Promise(r => setTimeout(r, 1000, Math.random() * 100 | 0));
(async () => {
console.time('xxx');
const [ result1, result2 ] = [ await getNum(), await getNum() ];
console.log(result1, result2);
console.timeEnd('xxx');
})();
(async () => {
console.time('yyy');
const [ result1, result2 ] = await Promise.all([ getNum(), getNum() ]);
console.log(result1, result2);
console.timeEnd('yyy');
})();
$('table').on('change', 'select', ({ target: t }) => {
const isNone = t.value === 'none';
$(t)
.closest('td')
[isNone ? 'nextAll' : 'next']()
.find('select')
.prop('disabled', isNone)
.val((i, val) => isNone ? 'none' : val);
});
document.querySelector('table').addEventListener('change', ({ target: t }) => {
if (t.tagName === 'SELECT') {
const isNone = t.value === 'none';
const { cellIndex: i, parentNode: { children } } = t.closest('td');
[...children].slice(i + 1, isNone ? undefined : i + 2).forEach(n => {
const select = n.querySelector('select');
select.disabled = isNone;
select.value = isNone ? 'none' : select.value;
});
}
});
this.onWheel.bind(this) !== this.onWheel.bind(this) // true
<button id="button-1"
$('#botton-1').on('dblclick',
$('#example thead tr:eq(1) th').slice(2).each(... дальше всё как было
не проканало, то есть визуально все как надо но по факту поиск из фильтра стал работать не в той колонке
table.column(i)
, а table.column(i + 2)
. Или не полагаться на передаваемый индекс, а вычислять его самостоятельно, что-то вроде const index = $(this).closest('th').index()
.