Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON methods, toJSON #197

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update task.md
  • Loading branch information
ImVietnam authored Mar 8, 2023
commit 1801236d5af5c5f89ddeb10b070c768e93409043
14 changes: 7 additions & 7 deletions 1-js/05-data-types/12-json/2-serialize-event-circular/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Exclude backreferences
# Loại trừ phản hồi

In simple cases of circular references, we can exclude an offending property from serialization by its name.
Trong các trường hợp đơn giản của tham chiếu vòng tròn, chúng ta có thể loại trừ một thuộc tính vi phạm khỏi việc tuần tự hóa theo tên của nó.

But sometimes we can't just use the name, as it may be used both in circular references and normal properties. So we can check the property by its value.
Nhưng đôi khi chúng ta không thể chỉ sử dụng tên, vì nó có thể được sử dụng cả trong tham chiếu vòng và thuộc tính bình thường. Vì vậy, chúng ta có thể kiểm tra thuộc tính theo giá trị của nó.

Write `replacer` function to stringify everything, but remove properties that reference `meetup`:
Viết hàm `replacer` để xâu chuỗi mọi thứ, nhưng xóa các thuộc tính tham chiếu `meetup`:

```js run
let room = {
Expand All @@ -22,16 +22,16 @@ let meetup = {
};

*!*
// circular references
// tham chiếu vòng
room.occupiedBy = meetup;
meetup.self = meetup;
*/!*

alert( JSON.stringify(meetup, function replacer(key, value) {
/* your code */
/* mã của bạn */
}));

/* result should be:
/* kết quả nên là:
{
"title":"Conference",
"occupiedBy":[{"name":"John"},{"name":"Alice"}],
Expand Down