<div class="container">
<input maxlength="10">
</div>
const container = document.querySelector('.container');
const input = container.querySelector('input').cloneNode();
container.addEventListener('input', ({ target: t }) => {
if (t.value.length === +t.maxLength) {
const nextInput = t.nextElementSibling || input.cloneNode();
t.insertAdjacentElement('afterend', nextInput);
nextInput.focus();
}
});
const a = v1 => {
const f = v2 => a(v1 + v2);
f.valueOf = () => v1;
return f;
};
a(1)(2)(3)(4)(5) * 6 // 90
10 + a(4)(5)(6) // 25
Math.pow(a(8)(1), 3) // 729
a(4)(6) - a(3) // 7
file['selected'] = true
this.$set(file, 'selected', true)
Переписал код с ES5 на ES6
data: () => ({
show: false
})
<button @click="show = !show">{{ show ? 'hide' : 'show' }}</button>
<my-component v-if="show"></my-component>
data: () => ({
items: []
}),
methods: {
add() {
this.items.push(...);
}
}
<button @click="add">add</button>
<my-component v-for="n in items"></my-component>
const adjacentElementsProduct = arr => arr
.sort((a, b) => a - b)
.slice(-2)
.reduce((acc, n) => acc * n, 1);
const fileIndex = this.files.indexOf(fileInArr);
this.$set(this.files, fileIndex, response.data);
input:focus::placeholder {
color: transparent;
}
arr = arr.filter(n => n.id !== ID);
arr.splice(arr.findIndex(n => n.id === ID), 1);
const index = arr.findIndex(n => n.id === ID);
if (index !== -1) {
arr.splice(index, 1);
}
function toggleClass(selector, className, delay) {
let index = -1;
return setInterval($items => {
$items.eq(index).removeClass(className);
index = (index + 1) % $items.length;
$items.eq(index).addClass(className);
}, delay, $(selector));
}
const intervalId = toggleClass('.wrap div', 'active', 300);
function toggleClass(selector, className, delay) {
const items = document.querySelectorAll(selector);
let index = ~-items.length;
return items.length
? setInterval(() => {
items[index].classList.remove(className);
index = -~index % items.length;
items[index].classList.add(className);
}, delay)
: null;
}