{"id":2111,"date":"2022-07-31T12:37:22","date_gmt":"2022-07-31T03:37:22","guid":{"rendered":"http:\/\/www.agile-software.site\/?p=2111"},"modified":"2023-08-09T13:27:06","modified_gmt":"2023-08-09T04:27:06","slug":"promise","status":"publish","type":"post","link":"https:\/\/agile-software.net\/?p=2111","title":{"rendered":"Promise"},"content":{"rendered":"\n<p>Promise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001\u4f5c\u6210\u3055\u308c\u305f\u6642\u70b9\u3067\u306f&nbsp;<code>Pending<\/code>&nbsp;\uff08\u5f85\u6a5f\uff09\u72b6\u614b\u3067\u3059\u3002<br>\u305d\u306e\u5f8c\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u5185\u3067<strong><span class=\"marker\">&nbsp;<code>resolve()<\/code>&nbsp;\uff08\u89e3\u6c7a\uff09<\/span><\/strong>\u3055\u308c\u305f\u6642\u70b9\u3067&nbsp;<code>Fulfilled<\/code>&nbsp;\u72b6\u614b\u3068\u306a\u308a\u3001<code>then()<\/code>&nbsp;\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<br>\u9006\u306b<strong><span class=\"marker\">&nbsp;<code>reject()<\/code>&nbsp;\uff08\u5931\u6557\uff09<\/span><\/strong>\u304c\u547c\u3073\u51fa\u3055\u308c\u305f\u6642\u70b9\u3067&nbsp;<code>Rejected<\/code>&nbsp;\u72b6\u614b\u3068\u306a\u308a\u3001<code>catch()<\/code>&nbsp;\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059<br>\u3064\u307e\u308a\u3001Promise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u306b\u5bfe\u5fdc\u3057\u3066\u3001\u305d\u308c\u305e\u308c\u6210\u529f\u6642\u3001\u5931\u6557\u6642\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3076\u3053\u3068\u3067\u51e6\u7406\u306e\u5206\u5c90\u3092\u5b9f\u73fe\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"760\" height=\"300\" src=\"http:\/\/www.agile-software.site\/wp-content\/uploads\/2022\/07\/Pending.png\" alt=\"\" class=\"wp-image-2112\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Promise.resolve()<\/h2>\n\n\n\n<p><code>Promise.resolve()<\/code>&nbsp;\u306fPromise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u304c\u3001\u6e21\u3059\u5f15\u6570\u306b\u3088\u3063\u3066\u8fd4\u3055\u308c\u308bPromise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u4e0b\u8a18\u306e\u3088\u3046\u306b\u5909\u308f\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><strong>\u6e21\u3059\u5f15\u6570<\/strong><\/th><th><strong>\u8fd4\u3055\u308c\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u72b6\u614b<\/strong><\/th><\/tr><\/thead><tbody><tr><td>Promise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/td><td><br>\u53d7\u3051\u53d6\u3063\u305fPromise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u305d\u306e\u307e\u307e\u8fd4\u3059<\/td><\/tr><tr><td>thenable\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/td><td>\u65b0\u305f\u306apromise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u3057\u3066\u8fd4\u3059<\/td><\/tr><tr><td>\u305d\u306e\u4ed6\u306e\u5024(\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3084null\u7b49\u3082\u542b\u3080)<\/td><td>\u305d\u306e\u5024\u3067Fulfilled\u3068\u306a\u3063\u305f\u65b0\u305f\u306apromise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u308a\u8fd4\u3059<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Promise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h3>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">thenable\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h3>\n\n\n\n<p><code>then()<\/code>&nbsp;\u306f\u6b21\u306e\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u65b0\u3057\u3044Promise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\n<ul class=\"wp-block-list\">\n<li>\u3069\u306e\u3088\u3046\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u3066\u3044\u308b\u304b\u3068\u3044\u3046\u3068\u3001<code>then<\/code>&nbsp;\u306b\u6e21\u3055\u308c\u305f\u95a2\u6570\u304c&nbsp;<code>return<\/code>&nbsp;\u3057\u305f\u5024\u3092\u3001<code>Promise.resolve()<\/code>&nbsp;\u306b\u6e21\u3057\u3066\u65b0\u3057\u3044Promise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u3066\u3044\u308b<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u975e\u540c\u671f<\/strong>\u3067\u5b9f\u884c\u3055\u308c\u308b<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u57fa\u672c\u69cb\u6587<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>function promiseFunction(value) {\n  const promise = new Promise(function(resolve, reject) {  \/\/Promise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u521d\u671f\u5316\u3059\u308b\n    setTimeout(function() {\n      if (value !==null) {\n        resolve(true);\n      } else {\n        reject(false);\n      }\n    }, 1000);\n  });\n  return promise;  \/\/Promise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\n}\n\npromiseFunction()\n  .then(function(response) {\n    (\u6210\u529f\u6642\u306e\u51e6\u7406)\n  })\n  .catch(function(error) {\n    (\u5931\u6557\u6642\u306e\u51e6\u7406)\n  })\n  .finally(function() {\n    (\u51e6\u7406\u7d50\u679c\u306b\u95a2\u308f\u3089\u305a\u5fc5\u305a\u5b9f\u884c\u3057\u305f\u3044\u51e6\u7406)\n  });<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Promise\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001\u4f5c\u6210\u3055\u308c\u305f\u6642\u70b9\u3067\u306fPending\uff08\u5f85\u6a5f\uff09\u72b6\u614b\u3067\u3059\u3002\u305d\u306e\u5f8c\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u5185\u3067resolve()\uff08\u89e3\u6c7a\uff09\u3055\u308c\u305f\u6642\u70b9\u3067Fulfill<\/p>\n","protected":false},"author":1,"featured_media":2785,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jin_ogp_image_url":"","_jin_last_featured_id":0,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-2111","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/2111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2111"}],"version-history":[{"count":2,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/2111\/revisions"}],"predecessor-version":[{"id":2786,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/2111\/revisions\/2786"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/media\/2785"}],"wp:attachment":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}