Proxy construct()
Intercepts the new operator.
construct(obj, args, newTarget) {
return Reflect.construct(obj, args, newTarget);
}
Triggered by:
nex proxy()
Parameters
- obj - the constructor object
- args - the array of arguments passed
- newTarget - the constructor
Must Return
- An Object (The new instance)
The construct trap only runs when you use new.
const obj = {} // No trap
Object.create() // No trap
class User {};
new User(); // No trap
Proxy Handler Methods:
handler.apply()
handler.construct()
handler.defineProperty()
handler.deleteProperty()
handler.get()
handler.getOwnPropertyDescriptor()
handler.getPrototypeOf()
handler.has()
handler.isExtensible()
handler.ownKeys()
handler.preventExtensions()
handler.set()
handler.setPrototypeOf()
Browser Support
handler.construct() is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers since June 2017:
| Chrome 51 |
Edge 15 |
Firefox 54 |
Safari 10 |
Opera 38 |
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |