Promise.prototype
Thuộc tính Promise
.prototype
biểu diễn nguyên mẫu (prototype) cho hàm khởi tạo của Promise
.
Property attributes of Promise.prototype |
|
---|---|
Writable | no |
Enumerable | no |
Configurable | no |
Mô tả
Mỗi đối tượng Promise
được kế thừa từ Promise.prototype
. Ta có thể sử dụng nguyên mẫu của hàm khởi tạo để thêm vào các thuộc tính hoặc phương thức mới cho đối tượng Promise
.
Thuộc tính
Promise.prototype.constructor
- Trả ra hàm khởi tạo một nguyên mẫu đối tượng. Mặc định là hàm
Promise
.
Phương thức
Promise.prototype.catch(onRejected)
- Thêm một hàm phản hồi lỗi cho promise và trả ra một promise mới chứa kết quả được truyền vào hàm phản hồi đó sau khi thao tác xử lý của promise kết thúc.
Promise.prototype.then(onFulfilled, onRejected)
(en-US)- Thêm một hàm phản hồi (có thể là thành công hoặc thất bại) và trả ra một promise mới chứa kết quả là kết quả thực thi của promise sau khi tác vụ kết thúc. Trong đó onFulfilled sẽ có đầu vòa là kết quả xử lý thành công, còn onRejected có đầu vòa là kết quả xử lý thất bại.
Đặc tả
Đặc tả | Trạng thái | Ghi chú |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Promise.prototype' in that specification. |
Standard | Initial definition. |
ECMAScript (ECMA-262) The definition of 'Promise.prototype' in that specification. |
Living Standard |
Trình duyệt tương thích
No compatibility data found for .
Check for problems with this page or contribute missing data to mdn/browser-compat-data.
To contribute to this compatibility data, please write a pull request against this file: https://github.com/mdn/browser-compat-data/blob/master/javascript/promise.json.