reflect.getprototypeof

中文文档
1.0.10发布于 2025/01/03MITCommonJS近 30 天下载 3.4亿

An ES2015 mostly-spec-compliant Reflect.getPrototypeOf sham/polyfill/replacement that works in as many engines as possible

原始使用文档

reflect.getprototypeof Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

An ES2015 mostly-spec-compliant Reflect.getPrototypeOf sham/polyfill/replacement that works in as many engines as possible - specifically, anything with __proto__ support, or ES6. Built-in types will also work correctly in older engines.

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec.

Example

var getPrototypeOf = require('reflect.getprototypeof');
var assert = require('assert');

assert.throws(() => getPrototypeOf(true));
assert.throws(() => getPrototypeOf(42));
assert.throws(() => getPrototypeOf(''));
assert.equal(getPrototypeOf(/a/g), RegExp.prototype);
assert.equal(getPrototypeOf(new Date()), Date.prototype);
assert.equal(getPrototypeOf(function () {}), Function.prototype);
assert.equal(getPrototypeOf([]), Array.prototype);
assert.equal(getPrototypeOf({}), Object.prototype);
var getPrototypeOf = require('reflect.getprototypeof');
var assert = require('assert');
/* when Reflect or Reflect.getPrototypeOf is not present */
if (typeof Reflect === 'object') { delete Reflect.getPrototypeOf; }
delete globalThis.Reflect;
var shimmed = getPrototypeOf.shim();
assert.equal(shimmed, getPrototypeOf.getPolyfill());

assert.throws(() => Reflect.getPrototypeOf(true));
assert.throws(() => Reflect.getPrototypeOf(42));
assert.throws(() => Reflect.getPrototypeOf(''));
assert.equal(Reflect.getPrototypeOf(/a/g), RegExp.prototype);
assert.equal(Reflect.getPrototypeOf(new Date()), Date.prototype);
assert.equal(Reflect.getPrototypeOf(function () {}), Function.prototype);
assert.equal(Reflect.getPrototypeOf([]), Array.prototype);
assert.equal(Reflect.getPrototypeOf({}), Object.prototype);
var getPrototypeOf = require('reflect.getprototypeof');
var assert = require('assert');
/* when Reflect.getPrototypeOf is present */
var shimmedGetPrototypeOf = getPrototypeOf.shim();
assert.equal(shimmedGetPrototypeOf, Reflect.getPrototypeOf);
assert.equal(Reflect.getPrototypeOf([]), Array.prototype);

Tests

Simply clone the repo, npm install, and run npm test

版本与发布记录

reflect.getprototypeof 共发布 11 个版本,首次发布于 2021/01/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.10latest2025/01/031.8 年前
1.0.92024/12/191.9 年前
1.0.82024/12/071.9 年前
1.0.72024/11/241.9 年前
1.0.62024/03/172 年前
1.0.52024/02/052 年前

关于 reflect.getprototypeof 的常见问题

reflect.getprototypeof 是什么?

An ES2015 mostly-spec-compliant Reflect.getPrototypeOf sham/polyfill/replacement that works in as many engines as possible

如何安装 reflect.getprototypeof?

在项目目录运行 npm install reflect.getprototypeof,或使用 pnpm add / yarn add / bun add。

reflect.getprototypeof 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/reflect.getprototypeof 是否存在。

reflect.getprototypeof 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

reflect.getprototypeof 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 0.4。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

reflect.getprototypeof 可以商用吗?

reflect.getprototypeof 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

reflect.getprototypeof 的下载量有多少?

根据 npm 官方下载统计,reflect.getprototypeof 在 2026/10/05 – 2026/11/03 这 30 天内被下载 338,759,524 次,日均约 11,291,984 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

reflect.getprototypeof 还在维护吗?

最新版本 1.0.10 发布于 2025/01/03(1.8 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/01/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。