ECMAScript 6 Meta Reflect&Proxy

ECMAScript 6 Meta Reflect&Proxy

Reflect

Reflect is a built-in object that provides methods for interceptable JavaScript operations. The methods are the same as those of proxy handlers. Reflect is not a function object, so it's not constructible.

Unlike most global objects, Reflect is not a constructor. You cannot use it with a new operator or invoke the Reflect object as a function. All properties and methods of Reflect are static (just like the Math object).

  1. Reflect.apply()

    • Calls a target function with arguments as specified by the args parameter. See also Function.prototype.apply().

  2. Reflect.construct()

    • The new operator as a function. Equivalent to calling new target(...args). Provides also the optional possibility to specify a different prototype.

  3. Reflect.get()

    • A function that returns the value of properties.

Proxy

The Proxy object is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc).

var p = new Proxy(target, handler);
  1. target - A target object to wrap with Proxy. It can be any sort of object, including a native array, a function or even another proxy.

  2. handler - An object whose properties are functions which define the behavior of the proxy when an operation is performed on it.

  3. Methonds

    1. handler.getPrototypeOf()


  1. ES6 Reflection in Depth

  2. MDN Reflect

  3. ES6 Katas

  4. ES6 Reflect API Tutorial

  5. Introducing Javascript ES6 Proxies

  6. https://www.sitepoint.com/es6-proxies/

标签: none

添加新评论