Slide 1

Slide 1 text

Proxy’s Black Magic @yayoc FR ropp-study

Slide 2

Slide 2 text

Proxy in ES6 Proxy is a special object which allow you customize operations. var p = new Proxy(target, handler); ▣ target ○ A target object ▣ handler ○ An object contains operations such as set and get

Slide 3

Slide 3 text

Handler functions 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()

Slide 4

Slide 4 text

Example: traceSetter 1. “Set” trap takes Object, Property and Value. 2. Reflect can execute original setter method.

Slide 5

Slide 5 text

Use case ▣ Validator ○ http://bit.ly/2mVPIpx ▣ Throw an error when accessing unknown property ○ http://bit.ly/2zwpaB2 ▣ Negative index for Array ○ http://bit.ly/2iJ5W0u ▣ Immutability ○ http://bit.ly/2hKxp14

Slide 6

Slide 6 text

Downside... Measurement script: http://bit.ly/2hZnBEa Around 14x slower rather than Object *I used Chrome to get an above score

Slide 7

Slide 7 text

▣ Proxy has a potential to make codes more simply ▣ Low level injecting may let us confuse ▣ As all browsers don’t support, we need a polyfill ▣ From performance perspective, It’s not so good to use Proxy for frequently usage Object. Conclusion

Slide 8

Slide 8 text

thanks! Any questions? You can find me at @yayoc [email protected]

Slide 9

Slide 9 text

Credits Special thanks to all the people who made and released these awesome resources for free: ▣ Presentation template by SlidesCarnival ▣ Photographs by Unsplash