`handler.construct()` 方法用于拦截`new` 操作符. 为了使new操作符在生成的Proxy对象上生效，用于初始化代理的目标对象自身必须具有[[Construct]]内部方法（即 `new target` 必须是有效的）。

## 语法

    var p = new Proxy(target, {
      construct: function(target, argumentsList, newTarget) {
      }
    });

### 参数

下面的参数将会传递给`construct`方法，`this`绑定在handler上。

`target`
  目标对象。
`argumentsList`
  constructor的参数列表。
`newTarget`
  最初被调用的构造函数，就上面的例子而言是p。

### 返回值

`construct` 方法必须返回一个对象。

## 描述

`handler.construct()` 方法用于拦截 `new`操作符。

### 拦截

该拦截器可以拦截以下操作:

- `new proxy(...args)`
- `Reflect.construct()`

### 约束

如果违反以下约定，代理将会抛出错误 `TypeError`:

- 必须返回一个对象.

## 示例

下面代码演示如何拦截 `new` 操作。

    var p = new Proxy(function() {}, {
      construct: function(target, argumentsList, newTarget) {
        console.log('called: ' + argumentsList.join(', '));
        return { value: argumentsList[0] * 10 };
      }
    });

    console.log(new p(1).value); // "called: 1"
                                 // 10

下面的代码违反了约定.

    var p = new Proxy(function() {}, {
      construct: function(target, argumentsList, newTarget) {
        return 1;
      }
    });

    new p(); // TypeError is thrown

下面的代码未能正确的初始化Proxy。Proxy初始化时，传给它的`target` 必须具有一个有效的constructor供`new`操作符调用。

    var p = new Proxy({}, {
      construct: function(target, argumentsList, newTarget) {
        return {};
      }
    });

    new p(); // TypeError is thrown, "p" is not a constructor

## 规范

Specification | Status | Comment
--- | --- | ---
ECMAScript 2015 (6th Edition, ECMA-262) [[Construct]] | Standard | Initial definition.
ECMAScript Latest Draft (ECMA-262) [[Construct]] | Draft |

## 浏览器兼容性

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
`construct` | Chrome Full support 49 | Edge Full support 12 | Firefox Full support 18 | IE No support No | Opera Full support 36 | Safari Full support 10 | WebView Android Full support 49 | Chrome Android Full support 49 | Edge Mobile Full support Yes | Firefox Android Full support 18 | Opera Android Full support 36 | Safari iOS Full support 10 | Samsung Internet Android Full support 5.0 | nodejs Full support 6.0.0

### Legend

Full support
  Full support
No support
  No support

## 相关主题

- `Proxy`
- `handler`
- `new` operator.
- `Reflect.construct()`