跳至主要內容

Reflect 元数据

小于 1 分钟featurees-proposal

Reflect 元数据open in new window

模块

类型

namespace Reflect {
  function defineMetadata(
    metadataKey: any,
    metadataValue: any,
    target: Object,
    propertyKey?: PropertyKey
  ): void;
  function getMetadata(
    metadataKey: any,
    target: Object,
    propertyKey?: PropertyKey
  ): any;
  function getOwnMetadata(
    metadataKey: any,
    target: Object,
    propertyKey?: PropertyKey
  ): any;
  function hasMetadata(
    metadataKey: any,
    target: Object,
    propertyKey?: PropertyKey
  ): boolean;
  function hasOwnMetadata(
    metadataKey: any,
    target: Object,
    propertyKey?: PropertyKey
  ): boolean;
  function deleteMetadata(
    metadataKey: any,
    target: Object,
    propertyKey?: PropertyKey
  ): boolean;
  function getMetadataKeys(
    target: Object,
    propertyKey?: PropertyKey
  ): Array<any>;
  function getOwnMetadataKeys(
    target: Object,
    propertyKey?: PropertyKey
  ): Array<any>;
  function metadata(
    metadataKey: any,
    metadataValue: any
  ): (target: Object, targetKey: string | symbol) => void;
}

入口点

core-js/proposals/reflect-metadata
core-js(-pure)/full/reflect/define-metadata
core-js(-pure)/full/reflect/delete-metadata
core-js(-pure)/full/reflect/get-metadata
core-js(-pure)/full/reflect/get-metadata-keys
core-js(-pure)/full/reflect/get-own-metadata
core-js(-pure)/full/reflect/get-own-metadata-keys
core-js(-pure)/full/reflect/has-metadata
core-js(-pure)/full/reflect/has-own-metadata
core-js(-pure)/full/reflect/metadata

示例

示例open in new window:

let object = {};
Reflect.defineMetadata("foo", "bar", object);
Reflect.ownKeys(object); // => []
Reflect.getOwnMetadataKeys(object); // => ['foo']
Reflect.getOwnMetadata("foo", object); // => 'bar'