aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/javascript/reference/global_objects/promise/resolve/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ru/web/javascript/reference/global_objects/promise/resolve/index.html')
-rw-r--r--files/ru/web/javascript/reference/global_objects/promise/resolve/index.html138
1 files changed, 138 insertions, 0 deletions
diff --git a/files/ru/web/javascript/reference/global_objects/promise/resolve/index.html b/files/ru/web/javascript/reference/global_objects/promise/resolve/index.html
new file mode 100644
index 0000000000..13a8ba9ee9
--- /dev/null
+++ b/files/ru/web/javascript/reference/global_objects/promise/resolve/index.html
@@ -0,0 +1,138 @@
+---
+title: Promise.resolve()
+slug: Web/JavaScript/Reference/Global_Objects/Promise/resolve
+tags:
+ - ECMAScript6
+ - JavaScript
+ - Обещание
+ - метод
+translation_of: Web/JavaScript/Reference/Global_Objects/Promise/resolve
+---
+<div>{{JSRef}}</div>
+
+<p>Метод <code><strong>Promise.resolve(value)</strong></code> возвращает {{jsxref("Promise")}} выполненый с переданным значением. Если переданное значение является thenable - обьект (т.е. имеет метод {{jsxref("Promise.then", "\"then\" method")}}), возвращаемое обещание будет следовать thenable - обьекту, принимая свое состояние; в ином случае возвращаемое обещание будет выполнено с переданным значением.</p>
+
+<h2 id="Синтаксис">Синтаксис</h2>
+
+<pre class="syntaxbox"><var>Promise.resolve(value)</var>;
+Promise.resolve(promise);
+Promise.resolve(thenable);
+</pre>
+
+<h3 id="Параметры">Параметры</h3>
+
+<dl>
+ <dt>value</dt>
+ <dd>Значение с которым будет выполнено обещание. Может также быть обещанием или обьект подобный обещанию (thenable - обьект имеющий метод then).</dd>
+</dl>
+
+<h3 id="Возращаемое_значение">Возращаемое значение</h3>
+
+<p>Выполненый с переданным значением {{jsxref("Promise")}}.</p>
+
+<h2 id="Описание">Описание</h2>
+
+<p><code>Метод Promise.resolve</code> возвращает выполненое обещание (<code>Promise</code>).</p>
+
+<h2 id="Примеры">Примеры</h2>
+
+<h3 id="Использование_метода_Promise.resolve">Использование метода <code>Promise.resolve</code></h3>
+
+<pre class="brush: js">Promise.resolve("Success").then(function(value) {
+ console.log(value); // "Success"
+}, function(value) {
+ // не будет вызвана
+});
+</pre>
+
+<h3 id="Выполнение_с_массивом">Выполнение с массивом</h3>
+
+<pre class="brush: js">var p = Promise.resolve([1,2,3]);
+p.then(function(v) {
+ console.log(v[0]); // 1
+});
+</pre>
+
+<h3 id="Выполнение_с_другим_обещанием_Promise">Выполнение с другим обещанием ( <code>Promise</code>)</h3>
+
+<pre class="brush: js">var original = Promise.resolve(true);
+var cast = Promise.resolve(original);
+cast.then(function(v) {
+ console.log(v); // true
+});
+</pre>
+
+<h3 id="Выполнение_с_thenable_объектом_и_выбрасывание_исключений">Выполнение с thenable объектом и выбрасывание исключений</h3>
+
+<pre class="brush: js">// Выполнение с thenable объектом
+var p1 = Promise.resolve({
+ then: function(onFulfill, onReject) { onFulfill("fulfilled!"); }
+});
+console.log(p1 instanceof Promise) // true
+
+p1.then(function(v) {
+ console.log(v); // "fulfilled!"
+ }, function(e) {
+ // не вызывается
+});
+
+// Thenable объект выбрасывает исключение
+// перед вызовом колбека Promise resolves
+var thenable = { then: function(resolve) {
+ throw new TypeError("Throwing");
+ resolve("Resolving");
+}};
+
+var p2 = Promise.resolve(thenable);
+p2.then(function(v) {
+ // не вызывается
+}, function(e) {
+ console.log(e); // TypeError: Throwing
+});
+
+// Thenable объект выбрасывает исключение
+// после вызова колбека Promise resolves
+var thenable = { then: function(resolve) {
+ resolve("Resolving");
+ throw new TypeError("Throwing");
+}};
+
+var p3 = Promise.resolve(thenable);
+p3.then(function(v) {
+ console.log(v); // "Resolving"
+}, function(e) {
+ // не вызывается
+});
+</pre>
+
+<h2 id="Спецификация">Спецификация</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-promise.resolve', 'Promise.resolve')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td>Initial definition in an ECMA standard.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-promise.resolve', 'Promise.resolve')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Совместимость_с_браузерами">Совместимость с браузерами</h2>
+
+<p>{{Compat("javascript/promise","Promise.resolve")}}</p>
+
+<h2 id="Смотри_также">Смотри также</h2>
+
+<ul>
+ <li>{{jsxref("Promise")}}</li>
+</ul>