class Scrolling {
offset = null;
scrolls() {
const isOffset = pageYOffset > 100 ? "offsetOne" : "offsetSecond";
if (this.offset != isOffset) {
this[isOffset]({
registion: document.querySelector("#registion"),
vhod: document.querySelector("#vhod"),
});
this.offset = isOffset;
}
}
offsetOne({ registion, vhod }) {
registion.style.display = "none";
vhod.style.cssText = "background:none;width:30px";
vhod.innerHTML = "<img style='width: 20px; height: 20px;' src='SiteImage/logo_vhod.svg'>";
PanelMenuLinks.style.cssText = "background:none;z-index:-1;margin-top:-45px;font-size:13px;color:#fff;border-top:0;";
block_panel_menu_children.style.top = "10px";
//block_panel_menu - заменить на класс.
document.querySelectorAll("#block_panel_menu").forEach((item) => (item.style.height = "49px"));
document.querySelector("#logotip").style.cssText = "opacity: 0;margin-top:-20px;";
document.querySelector("header").style.height = "50px";
}
offsetSecond({ registion, vhod }) {
registion.style.display = "block";
vhod.style.cssText = "background:#626262;width:100px";
vhod.innerHTML = "Регистрация";
PanelMenuLinks.style.cssText = "background:#E7E7E7;margin-top:0px;font-size:18px;color:#000;border-top:10px solid #fff;";
block_panel_menu_children.style.top = "20px";
//block_panel_menu - заменить на класс.
document.querySelectorAll("#block_panel_menu").forEach((item) => (item.style.height = "70px"));
document.querySelector("#logotip").style.cssText = "opacity:1;margin-top:0px;";
document.querySelector("header").style.height = "70px";
}
}
const scroll = new Scrolling();
window.addEventListener("scroll", scroll.scrolls.bind(scroll), false);
Как избегать foreach внутри foreach?
Очень часто вижу на разных форумах, в коммах в вк и тд юзать цикл внутри цикла не правильно
Каким образом можно сделать это по другому(правильно) ?
var imageFromInternet = GetImageByUrl("http://example.com/big-image.bmp");
picture.image = imageFromInternet;
arr.pop();
// или
arr.length -= !!arr.length;
// или
arr.splice(-1);
const count = сколько надо удалить;
):for (let i = count; --i >= 0 && arr.length; arr.pop()) ;
// или
arr.length -= Math.max(0, Math.min(arr.length, count));
// или
count > 0 && arr.splice(-count);
const getMinimumUniqueSum = arr => [...arr]
.sort((a, b) => a - b)
.reduce((acc, n) => (acc[1] += acc[0] = Math.max(acc[0] + 1, n), acc), [ -Infinity, 0 ])
.pop();
post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
Оба дженерика имеют типы по умолчанию, а значит если их не указать именно они и будут использоватьсяaxios.post<ResponseApi>(/* ... */)
мы явно указываем, что T
- это тип ResponseApi
, а R берется по умолчанию, то есть AxiosResponse<T>
, что в нашем случае соответствует AxiosResponse<ResponseApi>
, а если и дальше развернуть, то выходит, что R
- это{
data: ResponseApi;
status: number;
statusText: string;
headers: any;
config: AxiosRequestConfig;
request?: any;
}
он и попадает в возвращаемый тип, обернутый в Promise, но TS знает про поведение await и деструктуризации, а следовательно без проблем вычисляет тип для data
- ResponseApi
first = utils.random(1, 10)
second = utils.random(11, 20)
third = utils.random(21, 30)