Package detail

reflect.getprototypeof

es-shims99.2mMIT1.0.10

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

Reflect.getPrototypeOf, Object.getPrototypeOf, proto, __proto__

readme

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.0.10 - 2025-01-02

Commits

  • [Refactor] use es-object-atoms and get-proto directly 2c55da0
  • [Refactor] use isObject helper instead of Type e4c24a4
  • [Deps] update es-abstract, get-intrinsic 54005fb
  • [Deps] update es-abstract e71b3b7

v1.0.9 - 2024-12-18

Commits

  • [Fix] avoid a crash with node --disable-proto=throw flag 73f449d
  • [Deps] update dunder-proto, es-abstract, get-intrinsic, which-builtin-type 80c8227

v1.0.8 - 2024-12-06

Commits

  • [Refactor] share the getDunderProto helper f4be71b
  • [Refactor] extract helper to dunder-proto 51dcd35
  • [Deps] update call-bind c06e8d3
  • [Deps] update gopd c951a70
  • [Deps] update gopd 8bd7b85
  • [Deps] update which-builtin-type f46f624

v1.0.7 - 2024-11-23

Commits

  • [Fix] cache Object.prototype[__proto__] getter 68acea1
  • [Tests] remove unused test file 055596a
  • [actions] split out node 10-20, and 20+ 99a57c2
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, auto-changelog, tape fe4bb92
  • [Deps] update es-abstract, globalthis, which-builtin-type 867aeb3
  • [Tests] replace aud with npm audit 5129c11
  • [Deps] remove unused dep; add missing dev dep 23cf537
  • [Dev Deps] add missing peer dep 18862fa

v1.0.6 - 2024-03-16

Commits

  • [meta] remove useless ESM cc16ab1
  • [Deps] update call-bind, es-abstract, es-errors, get-intrinsic ece7445
  • [Dev Deps] update tape a894b62

v1.0.5 - 2024-02-04

Commits

  • [Refactor] use es-errors where possible, so things that only need those do not need get-intrinsic 08735cb
  • [Deps] update call-bind, define-properties, es-abstract, get-intrinsic b5700ec
  • [Dev Deps] update aud, npmignore, tape f80fcbb

v1.0.4 - 2023-08-30

Commits

  • [Deps] update define-properties, es-abstract, get-intrinsic 325044f
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, aud, tape 56b9555

v1.0.3 - 2022-11-07

Commits

  • [actions] reuse common workflows 0a76d97
  • [meta] use npmignore to autogenerate an npmignore file c4861b4
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, safe-publish-latest, tape e5352ab
  • [actions] update codecov uploader dbcedf8
  • [Deps] update define-properties, es-abstract, globalthis, which-builtin-type 84fbfab
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, tape 75dc8a3
  • [actions] update rebase action to use reusable workflow 49463a7
  • [Dev Deps] update @es-shims/api adf75cb

v1.0.2 - 2021-10-03

Commits

v1.0.1 - 2021-09-08

Commits

  • [actions] use node/install instead of node/run; use codecov action 86f4aa3
  • [Refactor] remove unnecessary ESM files 162e4bf
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, aud, auto-changelog, tape 5515a8d
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, tape db05b43
  • [readme] add github actions/codecov badges d9ea295
  • [Deps] update es-abstract, which-builtin-type 1753dee
  • [Dev Deps] update eslint, tape 4bce2db
  • [Deps] update es-abstract, get-intrinsic 1dca685
  • [meta] use prepublishOnly script for npm 7+ 1108273
  • [actions] update workflows 8674d66
  • [Deps] update es-abstract 4e4fdcf

v1.0.0 - 2021-01-12

Commits

  • es-shims initial commit ffd0b98
  • Initial commit 64c868f
  • [meta] add Automatic Rebase and Require Allow Edits workflows 6a006b4
  • [meta] Only apps should have lockfiles d1a29b5
  • [Deps] update call-bind bfcc1a0