From 95aca4b4d8fa62815d4bd412fff1a364f842814a Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 29 Apr 2021 16:16:42 -0700 Subject: remove retired locales (#699) --- .../global_objects/promise/finally/index.html | 95 ---------------------- 1 file changed, 95 deletions(-) delete mode 100644 files/vi/web/javascript/reference/global_objects/promise/finally/index.html (limited to 'files/vi/web/javascript/reference/global_objects/promise/finally') diff --git a/files/vi/web/javascript/reference/global_objects/promise/finally/index.html b/files/vi/web/javascript/reference/global_objects/promise/finally/index.html deleted file mode 100644 index a8796382a2..0000000000 --- a/files/vi/web/javascript/reference/global_objects/promise/finally/index.html +++ /dev/null @@ -1,95 +0,0 @@ ---- -title: Promise.prototype.finally() -slug: Web/JavaScript/Reference/Global_Objects/Promise/finally -translation_of: Web/JavaScript/Reference/Global_Objects/Promise/finally ---- -
{{JSRef}}
- -

Phương thức finally() trả về một {{jsxref("Promise")}}. Một khi promise được thực hiện (settle), dù kết quả là fulfilled hay rejected, thì hàm callback đã chỉ định sẽ được thực thi. Đây là cách để làm cho một đoạn code phải được thực thi sau khi Promise hoàn thành, dù kết quả là fulfilled hay rejected.

- -

Cách này giúp bạn tránh phải viết những dòng code trùng lặp giữa hai phương thức xử lý {{jsxref("Promise.then", "then()")}} và {{jsxref("Promise.catch", "catch()")}}.

- -

Syntax

- -
p.finally(onFinally);
-
-p.finally(function() {
-   // settled (fulfilled or rejected)
-});
-
- -

Parameters

- -
-
onFinally
-
Một {{jsxref("Function")}} được gọi khi Promise được thực hiện
-
- -

Return value

- -

Return a {{jsxref("Promise")}} whose finally handler is set to the specified function, onFinally.

- -

Description

- -

Phương thức finally() hữu ích khi bạn muốn xử lý công việc sau khi promise được thực hiện.

- -

Phương thức finally() cũng tương tự như việc gọi .then(onFinally, onFinally) , tuy nhiên có một số sự khác biệt:

- - - -
-

Note: Một throw (hoặc trả về một promise bị reject) trong callback finally sẽ reject cái promise mới với lý do reject được chỉ định khi gọi throw().

-
- -

Examples

- -
let isLoading = true;
-
-fetch(myRequest).then(function(response) {
-    var contentType = response.headers.get("content-type");
-    if(contentType && contentType.includes("application/json")) {
-      return response.json();
-    }
-    throw new TypeError("Oops, we haven't got JSON!");
-  })
-  .then(function(json) { /* process your JSON further */ })
-  .catch(function(error) { console.log(error); })
-  .finally(function() { isLoading = false; });
-
-
- -

Specifications

- - - - - - - - - - - - - - -
SpecificationStatusComment
TC39 proposalStage 4 
- -

Browser compatibility

- - - -

{{Compat("javascript.builtins.Promise.finally")}}

- -

See also

- - -- cgit v1.2.3-54-g00ecf