winPositions.some(n => n.every(m => xPositions.includes(m)))
if (localStorage.getItem('mediaObjViewSeen') === true) {
Ключи и значения всегда строки
data: () => ({
view: localStorage.getItem('view') || 'CardsView',
// ...
}),
watch: {
view: val => localStorage.setItem('view', val),
},
data: () => ({
views: [
{
name: 'CardsView',
btnClass: 'btn-left',
img: '...',
},
{
name: 'MediaObjView',
btnClass: 'btn-right',
img: '...',
},
],
// ...
}),
<button
v-for="n in views"
:class="[ n.btnClass, view === n.name ? 'btn-active' : '' ]"
@click="view = n.name"
>
<img :src="n.img">
</button>
view
в TweetPreview
, используете его значение как имя компонента:<component
:is="view"
:tweet="tweet"
/>
const wrapper = document.querySelector('.block');
const blockSelector = '.block_one';
const activeClass = 'active';
wrapper.addEventListener('mouseover', onHover);
wrapper.addEventListener('mouseout', onHover);
function onHover({ type, target }) {
const block = type === 'mouseover' && target.closest(blockSelector);
this.querySelectorAll(blockSelector).forEach(n => {
n.classList.toggle(activeClass, !!block && n !== block);
});
}
.block:has(.block_one:hover) .block_one:not(:hover) {
/* сюда переносим стили того класса, который через js добавлялся */
}
computed: {
task() {
return new Proxy(this.value, {
set: (target, prop, value) => {
this.$emit('input', { ...target, [prop]: value });
return true;
},
});
},
},
v-model
соответствующих полей ввода):<input type="checkbox" v-model="task.done">
<button v-if="task.done" @click="$emit('delete')">delete</button>
<task-element
v-for="(n, i) in todos"
v-model="todos[i]"
@delete="todos.splice(i, 1)"
></task-element>
document.querySelectorAll('.number').forEach(n => {
n.innerText = n.innerText.replace(/\d+/g, m => (+m).toLocaleString());
});
for (const n of document.getElementsByClassName('number')) {
n.textContent = n.textContent.replace(/\d(?=(\d{3})+(\D|$))/g, '$& ');
}
$headers = array_column($data[0]['pages'], 'name');
$columns = array_column($data[0]['pages'], 'attribute');
$rowCount = max(array_map('count', $columns));
$headersHTML = implode('', array_map(function($n) {
return "<th>$n</th>";
}, $headers));
$rowsHTML = implode('', array_map(function($i) use($columns) {
return "
<tr>".implode('', array_map(function($n) use($i) {
return "<td>".($n[$i] ?? '')."</td>";
}, $columns))."
</tr>";
}, range(0, $rowCount - 1)));
echo "
<table>
<thead>
<tr>$headersHTML</tr>
</thead>
<tbody>$rowsHTML</tbody>
</table>";
fetch('https://api.novaposhta.ua/v2.0/json/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
modelName: 'Address',
calledMethod: 'getWarehouses',
methodProperties: {
CityName: document.querySelector('.myCityName').textContent,
},
apiKey: '',
}),
})
.then(r => r.json())
.then(r => {
document.querySelector('.mySelect').innerHTML = r.data
.map(n => `<option>${n.Description}</option>`)
.join('');
});
setInterval(tesla.moveRight,30)
setInterval(tesla.moveRight.bind(tesla), 30)
setInterval(() => tesla.moveRight(), 30)
class Car {
...
moveRight = () => {
...
}
}
Библиотеки и фреймворки (React, Vue, Redux...) даются очень тяжело.
Нравится работать с чистым js
используется для получения и установки инлайновых стилей
когда нажимаю повторно чтобы остановить музыку, она не останавливается
const result = arr
.reduce((acc, n, i, a) => (
a[i - 1] !== n && acc.push([ n, 0 ]),
acc[acc.length - 1][1]++,
acc
), [])
.map(([ v, c ]) => c === 1 ? v : Array(c).fill(v));
const result = arr
.reduce((acc, n, i, a) => (
a[i - 1] === n || acc.push([]),
acc[acc.length - 1].push(n),
acc
), [])
.map(n => n.length === 1 ? n[0] : n);
const result = arr.reduce((acc, n, i, a) => {
const prev = n === a[i - 1];
const next = n === a[i + 1];
!prev && next && acc.push([]);
(prev || next ? acc[acc.length - 1] : acc).push(n);
return acc;
}, []);
const length = 48;
const step = 30;
const locale = 'en-US';
const options = {
hour: '2-digit',
minute: '2-digit',
};
const times = Array.from({ length }, (_, i) => {
return new Date(0, 0, 0, 0, step * i).toLocaleTimeString(locale, options);
});
// или
const times = Array.from({ length }, function() {
return this[1].format(this[0].setMinutes(this[0].getMinutes() + step));
}, [ new Date(0, 0, 0, 0, -step), new Intl.DateTimeFormat(locale, options) ]);