function rgbaToAndroid1(rgba) {
const c = new Uint8Array([
rgba[2],
rgba[1],
rgba[0],
Math.round(rgba[3] * 255)
]);
return new Uint32Array(c.buffer)[0];
}
// либо
function rgbaToAndroid2(rgba) {
let color = 0;
for (let i = 0; i < 3; i++) {
color += rgba[i] * 2 ** ((2 - i) * 8);
}
color += Math.round(rgba[3] * 255) * 2 ** (3 * 8);
return color;
}
console.log(rgbaToAndroid1([255, 122, 107, 1]));
console.log(rgbaToAndroid2([255, 122, 107, 1]));
localStorage.setItem( 'name', value ); // пишите что хотите
localStorage.getItem( 'name' ); // читайте
localStorage.setItem( 'name', JSON.stringify( object )); // пишите в т.ч. объект
let object = JSON.parse( localStorage.getItem( 'name' ) ); // читайте в т.ч. объект
$('a1').on('click', product);
range.setAttribute('max', video.duration);
video.onloadeddata = () => range.setAttribute('max', video.duration);
git rm --cached [filename]
git commit --amend
let checked = null;
$('input').click(function() {
checked = checked === this.value ? null : this.value;
this.checked = !!checked;
});
// или
document.querySelectorAll('input').forEach(function(n) {
n.addEventListener('click', this);
}, function({ target: t }) {
t.checked = !!(this[0] = this[0] === t ? null : t);
}.bind([]));
const $checkboxes = $('input').change(function() {
if (this.checked) {
$checkboxes.not(this).prop('checked', false);
}
});
// или
const checkboxes = document.querySelectorAll('input');
const onChange = e => checkboxes.forEach(n => n.checked &&= n === e.target);
checkboxes.forEach(n => n.addEventListener('change', onChange));
.filter
должен возвращать булево значение. TRUE - оставить элемент, FALSE - удалитьfunction Validation(arr) {
return arr.filter((el) => {
return typeof el.age === "number"
&& el.full_name !== undefined
&& el.full_name.charAt(0) === el.full_name.charAt(0).toUpperCase()
&& el.gender !== undefined
&& el.gender.charAt(0) === el.gender.charAt(0).toUpperCase()
&& el.note !== undefined
&& el.note.charAt(0) === el.note.charAt(0).toUpperCase()
&& el.state !== undefined
&& el.state.charAt(0) === el.state.charAt(0).toUpperCase()
&& el.city !== undefined
&& el.city.charAt(0) === el.city.charAt(0).toUpperCase()
&& el.country !== undefined
&& el.country.charAt(0) === el.country.charAt(0).toUpperCase()
}
function firstLetterIsUpper(str) {
return typeof(str) === 'string'
&& str.length
&& str.charAt(0) === str.charAt(0).toUpperCase()
}
function Validation(arr) {
return arr.filter((el) => {
return typeof el.age === "number"
&& firstLetterIsUpper(el?.full_name)
&& firstLetterIsUpper(el?.gender)
&& firstLetterIsUpper(el?.note)
&& firstLetterIsUpper(el?.state)
&& firstLetterIsUpper(el?.city)
&& firstLetterIsUpper(el?.country)
}
outline: none;
<div class="btn-group" role="group" aria-label="Basic radio toggle button group">
<input type="radio" class="btn-check" name="btnradio" id="btnradio1" autocomplete="off" checked>
<label class="btn btn-outline-primary shadow-none" for="btnradio1">Radio 1</label>
<input type="radio" class="btn-check" name="btnradio" id="btnradio2" autocomplete="off">
<label class="btn btn-outline-primary shadow-none" for="btnradio2">Radio 2</label>
<input type="radio" class="btn-check" name="btnradio" id="btnradio3" autocomplete="off">
<label class="btn btn-outline-primary shadow-none" for="btnradio3">Radio 3</label>
</div>
Стрелка=>
ничего не привязывает. У функции просто нетthis
.
При получении значенияthis
– оно, как обычная переменная, берётся из внешнего лексического окружения.
const obj = {
w() {
console.log('w', this);
},
x: function () {
console.log('x', this);
},
y: this,
z: () => {
console.log('z', this);
},
};
obj.w(); // obj
obj.x(); // obj
console.log('y', obj.y); // Window
obj.z(); // Window
this
тот же, что и снаружи:const a = this; // Window
const obj = {
b: this, // тоже Window
}
a === obj.b // true
<div id="test">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci alias aliquam est fugit mollitia nisi quam qui! Aliquam aliquid consequatur dolorem ea, expedita ipsam laborum, mollitia praesentium, quidem sed voluptas?</div>
<style>
#test {
color: red;
}
#test:hover {
color: green;
transition: color 3s ease;
}
</style>
#test {
color: black;
transition: color 1s ease;
}
#test:hover {
color: red;
transition: color 5s ease;
}