跳至主要內容

Reflect

大约 1 分钟featurees-standard

Reflect

模块

类型

namespace Reflect {
  function apply(
    target: Function,
    thisArgument: any,
    argumentsList: Array<any>
  ): any;
  function construct<A extends readonly any[], R>(
    target: new (...args: A) => R,
    argumentsList: A,
    newTarget?: new (...args: any) => any
  ): Object;
  function defineProperty(
    target: Object,
    propertyKey: PropertyKey,
    attributes: PropertyDescriptor
  ): boolean;
  function deleteProperty(target: Object, propertyKey: PropertyKey): boolean;
  function get(target: Object, propertyKey: PropertyKey, receiver?: any): any;
  function getOwnPropertyDescriptor(
    target: Object,
    propertyKey: PropertyKey
  ): PropertyDescriptor | void;
  function getPrototypeOf(target: Object): Object | null;
  function has(target: Object, propertyKey: PropertyKey): boolean;
  function isExtensible(target: Object): boolean;
  function ownKeys(target: Object): Array<string | symbol>;
  function preventExtensions(target: Object): boolean;
  function set(
    target: Object,
    propertyKey: PropertyKey,
    value: any,
    receiver?: any
  ): boolean;
  function setPrototypeOf(target: Object, proto: Object | null): boolean; // required __proto__ - IE11+
}

入口点

core-js(-pure)/es|stable|actual|full/reflect
core-js(-pure)/es|stable|actual|full/reflect/apply
core-js(-pure)/es|stable|actual|full/reflect/construct
core-js(-pure)/es|stable|actual|full/reflect/define-property
core-js(-pure)/es|stable|actual|full/reflect/delete-property
core-js(-pure)/es|stable|actual|full/reflect/get
core-js(-pure)/es|stable|actual|full/reflect/get-own-property-descriptor
core-js(-pure)/es|stable|actual|full/reflect/get-prototype-of
core-js(-pure)/es|stable|actual|full/reflect/has
core-js(-pure)/es|stable|actual|full/reflect/is-extensible
core-js(-pure)/es|stable|actual|full/reflect/own-keys
core-js(-pure)/es|stable|actual|full/reflect/prevent-extensions
core-js(-pure)/es|stable|actual|full/reflect/set
core-js(-pure)/es|stable|actual|full/reflect/set-prototype-of

示例

示例open in new window:

let object = { a: 1 };
Object.defineProperty(object, "b", { value: 2 });
object[Symbol("c")] = 3;
Reflect.ownKeys(object); // => ['a', 'b', Symbol(c)]

function C(a, b) {
  this.c = a + b;
}

let instance = Reflect.construct(C, [20, 22]);
instance.c; // => 42