`Promise.resolve(value)`方法返回一个以给定值解析后的`Promise` 对象。但如果这个值是个thenable（即带有then方法），返回的promise会“跟随”这个thenable的对象，采用它的最终状态（指resolved/rejected/pending/settled）；如果传入的value本身就是promise对象，则该对象作为Promise.resolve方法的返回值返回；否则以该值为成功状态返回promise对象。

The source for this interactive demo is stored in a GitHub repository. If you'd like to contribute to the interactive demo project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

## 语法

    Promise.resolve(value);
    Promise.resolve(promise);
    Promise.resolve(thenable);

### 参数

value

  将被`Promise`对象解析的参数。也可以是一个`Promise`对象，或者是一个thenable。

### 返回值

返回一个解析过带着给定值的`Promise`对象，如果返回值是一个promise对象，则直接返回这个Promise对象。

## 描述

静态方法 `Promise.resolve`返回一个解析过的`Promise`对象.

## 示例

### 使用静态方法`Promise.resolve`

    Promise.resolve("Success").then(function(value) {
      console.log(value); // "Success"
    }, function(value) {
      // 不会被调用
    });

### 对一个数组进行resolve

    var p = Promise.resolve([1,2,3]);
    p.then(function(v) {
      console.log(v[0]); // 1
    });

### Resolve另一个promise对象

    var original = Promise.resolve('我在第二行');
    var cast = Promise.resolve(original);
    cast.then(function(value) {
      console.log('value: ' + value);
    });
    console.log('original === cast ? ' + (original === cast));

    /*
    *  打印顺序如下，这里有一个同步异步先后执行的区别
    *  original === cast ? true
    *  value: 我在第二行
    */

### resolve thenable的对象们并抛出错误

    // Resolve一个thenable对象
    var p1 = Promise.resolve({
      then: function(onFulfill, onReject) { onFulfill("fulfilled!"); }
    });
    console.log(p1 instanceof Promise) // true, 这是一个Promise对象

    p1.then(function(v) {
        console.log(v); // 输出"fulfilled!"
      }, function(e) {
        // 不会被调用
    });

    // Thenable在callback之前抛出异常
    // Promise rejects
    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在callback之后抛出异常
    // 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) {
      // 不会被调用
    });

## 规范

Specification | Status | Comment
--- | --- | ---
ECMAScript 2015 (6th Edition, ECMA-262) Promise.resolve | Standard | ECMA标准中的首次定义
ECMAScript Latest Draft (ECMA-262) Promise.resolve | Standard |

## 浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Update compatibility data on GitHub

| Desktop | Mobile | Server
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | Node.js
`resolve` | Chrome Full support 32 | Edge Full support 12 | Firefox Full support 29 | IE No support No | Opera Full support 19 | Safari Full support 8 | WebView Android Full support 4.4.3 | Chrome Android Full support 32 | Edge Mobile Full support Yes | Firefox Android Full support 29 | Opera Android Full support Yes | Safari iOS Full support 8 | Samsung Internet Android Full support Yes | nodejs Full support 0.12

### Legend

Full support
  Full support
No support
  No support

## 参见

- `Promise`