created() {
const interval = setInterval(this.method, 5 * 60 * 1000);
this.$on('hook:beforeDestroy', () => clearInterval(interval));
},
return new this.constructor();This expression is not constructable. Type 'Function' has no construct signatures
const { constructor } = Object.getPrototypeOf(this);
return new constructor();
<div class="phone">8 (123) 111-22-33</div>
<div class="phone">8 (456) 444-55-66</div>
<div class="phone">8 (789) 777-88-99</div>document.querySelectorAll('.phone').forEach(n => {
const phone = n.innerHTML;
n.innerHTML = phone.slice(0, -4) + '... - <span>показать</span>';
n.querySelector('span').addEventListener('click', () => n.innerHTML = phone);
});
function filter(val) {
if (!(val instanceof Object)) {
return val;
}
const filtered = Object
.entries(val)
.map(n => [ n[0], filter(n[1]) ])
.filter(n => n[1]);
return filtered.length
? val instanceof Array
? filtered.map(n => n[1])
: Object.fromEntries(filtered)
: null;
}
const validator = (value, maxSize) =>
!(/[^а-яА-Яa-zA-Z0-9\s]/.test(value) || value.length > maxSize);if (validator(value, maxSize)) {
setTitle(value);
}const validator = (defaultValue, value, maxSize) =>
(/[^а-яА-Яa-zA-Z0-9\s]/.test(value) || value.length > maxSize)
? defaultValue
: value;setTitle(prevValue => validator(prevValue, value, maxSize));
methods: {
createAlphaIndex(num) {
const base = 26;
let str = '';
do {
const mod = num % base;
num = num / base | 0;
str = (mod ? String.fromCharCode('A'.charCodeAt(0) + mod - 1) : (--num, 'Z')) + str;
} while(num);
return str;
},
},<div v-for="i in 1000">{{ createAlphaIndex(i) }}</div>
const elements = document.querySelectorAll('.price');
const output = document.querySelector('.min-sum');output.textContent = Math.min(...Array.from(
elements,
n => parseFloat(n.textContent)
));
// или
output.innerText = Array.prototype.reduce.call(
elements,
(min, n) => (
n = +n.innerText.match(/[\d.]+/),
n < min ? n : min
),
Infinity
);
const parent = document.querySelector('ul');
const selector = '#elem';const elem = parent.querySelector(selector)?.nextElementSibling;
if (elem) {
const num = 1 + Array.prototype.indexOf.call(parent.children, elem);
elem.textContent = num + '. ' + elem.textContent;
}const elem = parent.querySelector(`${selector} + *`);
if (elem) {
let num = 1;
for (let n = elem; n = n.previousElementSibling; num++) ;
elem.insertAdjacentText('afterbegin', `${num}. `);
}const index = -~[...parent.children].findIndex(n => n.matches(selector));
if (index) {
parent.children[index]?.prepend(''.concat(-~index, '. '));
}
Как наиболее короче сделать...
generalDiv.innerHTML = newCats
.filter(n => n?.breeds.length)
.map(({ url, breeds: [ b ] }) => `
<div class="cat__item">
<div class="cat__img"><img src="${url}" alt="${b.name}"></div>
<div class="cat__name">${b.name}</div>
<div class="cat__temperament">${b.temperament}</div>
<div class="cat__live">${b.life_span}</div>
<div class="cat__origin">${b.origin}</div>
<div class="cat__description">${b.description}</div>
<div class="cat__wikipedia_url">${b.wikipedia_url}</div>
</div>
`)
.join('');
document.querySelector('form').addEventListener('change', e => {
const sum = Array.prototype.reduce.call(
e.currentTarget.querySelectorAll('input:checked'),
(acc, n) => acc + +n.value,
0
);
document.querySelector('#pSumma').innerText = `$${sum.toFixed(2)}`;
});
document.querySelectorAll('.g-project__words-moving').forEach(n => {
const html = n.querySelector('.words-moving__calm span').outerHTML.repeat(10);
n.querySelectorAll('.running-string-wrapp').forEach(m => m.innerHTML = html);
});.words-moving__calm span, вместо того, чтобы ограничиться только теми, которые лежат внутри текущего элемента .g-project__words-moving. Для исправления можно перенести объявление place в начало тела внешнего цикла, заменив при этом document на boxes[i].
Array.prototype.push.apply(
arr,
newArr.filter(n => !arr.some(m => m.id === n.id))
);arr.splice(0, arr.length, ...arr
.concat(newArr)
.reduce((acc, n) => acc.set(n.id, acc.get(n.id) ?? n), new Map)
.values()
);newArr.forEach(function(n) {
this.has(n.id) || (arr[arr.length] = n);
}, new Set(arr.map(n => n.id)));
.on('beforeChange', function(e, slick, currSlide, nextSlide) {
$('.tabs-content__item').hide().eq(nextSlide).fadeIn();
});