Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Добавление раздела: WeakRef & FinalizationRegistry#1899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Alexandre887 merged 6 commits intojavascript-tutorial:masterfromWOLFRIEND:master
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
448 changes: 448 additions & 0 deletions1-js/99-js-misc/09-weakref-finalizationregistry/article.md
View file
Open in desktop

Large diffs are not rendered by default.

Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
.app {
display: flex;
flex-direction: column;
gap: 16px;
}

.start-messages {
width: fit-content;
}

.window {
width: 100%;
border: 2px solid #464154;
overflow: hidden;
}

.window__header {
position: sticky;
padding: 8px;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #736e7e;
}

.window__title {
margin: 0;
font-size: 24px;
font-weight: 700;
color: white;
letter-spacing: 1px;
}

.window__button {
padding: 4px;
background: #4f495c;
outline: none;
border: 2px solid #464154;
color: white;
font-size: 16px;
cursor: pointer;
}

.window__body {
height: 250px;
padding: 16px;
overflow: scroll;
background-color: #736e7e33;
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
<!DOCTYPE HTML>
<html>

<head>
<meta charset="utf-8">
<link rel="stylesheet" href="index.css">
</head>

<body>

<div class="app">
<button class="start-messages">Начать отправку сообщений</button>
<div class="window">
<div class="window__header">
<p class="window__title">Сообщения:</p>
<button class="window__button">Закрыть</button>
</div>
<div class="window__body">
Нет сообщений.
</div>
</div>
</div>


<script type="module" src="index.js"></script>
</body>
</html>
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
const startMessagesBtn = document.querySelector('.start-messages'); // (1)
const closeWindowBtn = document.querySelector('.window__button'); // (2)
const windowElementRef = new WeakRef(document.querySelector(".window__body")); // (3)

startMessagesBtn.addEventListener('click', () => { // (4)
startMessages(windowElementRef);
startMessagesBtn.disabled = true;
});

closeWindowBtn.addEventListener('click', () => document.querySelector(".window__body").remove()); // (5)

const startMessages = (element) => {
const timerId = setInterval(() => { // (6)
if (element.deref()) { // (7)
const payload = document.createElement("p");
payload.textContent = `Сообщение: Статус системы OK: ${new Date().toLocaleTimeString()}`;
element.deref().append(payload);
} else { // (8)
alert("Элемент был удалён."); // (9)
clearInterval(timerId);
}
}, 1000);
};
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp