1 | # reflect.getprototypeof <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
---|
2 |
|
---|
3 | [![github actions][actions-image]][actions-url]
|
---|
4 | [![coverage][codecov-image]][codecov-url]
|
---|
5 | [![dependency status][deps-svg]][deps-url]
|
---|
6 | [![dev dependency status][dev-deps-svg]][dev-deps-url]
|
---|
7 | [![License][license-image]][license-url]
|
---|
8 | [![Downloads][downloads-image]][downloads-url]
|
---|
9 |
|
---|
10 | [![npm badge][npm-badge-png]][package-url]
|
---|
11 |
|
---|
12 | 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.
|
---|
13 |
|
---|
14 | This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the [spec](https://www.ecma-international.org/ecma-262/5.1/).
|
---|
15 |
|
---|
16 | ## Example
|
---|
17 |
|
---|
18 | ```js
|
---|
19 | var getPrototypeOf = require('reflect.getprototypeof');
|
---|
20 | var assert = require('assert');
|
---|
21 |
|
---|
22 | assert.throws(() => getPrototypeOf(true));
|
---|
23 | assert.throws(() => getPrototypeOf(42));
|
---|
24 | assert.throws(() => getPrototypeOf(''));
|
---|
25 | assert.equal(getPrototypeOf(/a/g), RegExp.prototype);
|
---|
26 | assert.equal(getPrototypeOf(new Date()), Date.prototype);
|
---|
27 | assert.equal(getPrototypeOf(function () {}), Function.prototype);
|
---|
28 | assert.equal(getPrototypeOf([]), Array.prototype);
|
---|
29 | assert.equal(getPrototypeOf({}), Object.prototype);
|
---|
30 | ```
|
---|
31 |
|
---|
32 | ```js
|
---|
33 | var getPrototypeOf = require('reflect.getprototypeof');
|
---|
34 | var assert = require('assert');
|
---|
35 | /* when Reflect or Reflect.getPrototypeOf is not present */
|
---|
36 | if (typeof Reflect === 'object') { delete Reflect.getPrototypeOf; }
|
---|
37 | delete globalThis.Reflect;
|
---|
38 | var shimmed = getPrototypeOf.shim();
|
---|
39 | assert.equal(shimmed, getPrototypeOf.getPolyfill());
|
---|
40 |
|
---|
41 | assert.throws(() => Reflect.getPrototypeOf(true));
|
---|
42 | assert.throws(() => Reflect.getPrototypeOf(42));
|
---|
43 | assert.throws(() => Reflect.getPrototypeOf(''));
|
---|
44 | assert.equal(Reflect.getPrototypeOf(/a/g), RegExp.prototype);
|
---|
45 | assert.equal(Reflect.getPrototypeOf(new Date()), Date.prototype);
|
---|
46 | assert.equal(Reflect.getPrototypeOf(function () {}), Function.prototype);
|
---|
47 | assert.equal(Reflect.getPrototypeOf([]), Array.prototype);
|
---|
48 | assert.equal(Reflect.getPrototypeOf({}), Object.prototype);
|
---|
49 | ```
|
---|
50 |
|
---|
51 | ```js
|
---|
52 | var getPrototypeOf = require('reflect.getprototypeof');
|
---|
53 | var assert = require('assert');
|
---|
54 | /* when Reflect.getPrototypeOf is present */
|
---|
55 | var shimmedGetPrototypeOf = getPrototypeOf.shim();
|
---|
56 | assert.equal(shimmedGetPrototypeOf, Reflect.getPrototypeOf);
|
---|
57 | assert.equal(Reflect.getPrototypeOf([]), Array.prototype);
|
---|
58 | ```
|
---|
59 |
|
---|
60 | ## Tests
|
---|
61 | Simply clone the repo, `npm install`, and run `npm test`
|
---|
62 |
|
---|
63 | [package-url]: https://npmjs.org/package/reflect.getprototypeof
|
---|
64 | [npm-version-svg]: https://versionbadg.es/es-shims/Reflect.getPrototypeOf.svg
|
---|
65 | [deps-svg]: https://david-dm.org/es-shims/Reflect.getPrototypeOf.svg
|
---|
66 | [deps-url]: https://david-dm.org/es-shims/Reflect.getPrototypeOf
|
---|
67 | [dev-deps-svg]: https://david-dm.org/es-shims/Reflect.getPrototypeOf/dev-status.svg
|
---|
68 | [dev-deps-url]: https://david-dm.org/es-shims/Reflect.getPrototypeOf#info=devDependencies
|
---|
69 | [npm-badge-png]: https://nodei.co/npm/reflect.getprototypeof.png?downloads=true&stars=true
|
---|
70 | [license-image]: https://img.shields.io/npm/l/reflect.getprototypeof.svg
|
---|
71 | [license-url]: LICENSE
|
---|
72 | [downloads-image]: https://img.shields.io/npm/dm/reflect.getprototypeof.svg
|
---|
73 | [downloads-url]: https://npm-stat.com/charts.html?package=reflect.getprototypeof
|
---|
74 | [codecov-image]: https://codecov.io/gh/es-shims/Reflect.getPrototypeOf/branch/main/graphs/badge.svg
|
---|
75 | [codecov-url]: https://app.codecov.io/gh/es-shims/Reflect.getPrototypeOf/
|
---|
76 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Reflect.getPrototypeOf
|
---|
77 | [actions-url]: https://github.com/es-shims/Reflect.getPrototypeOf/actions
|
---|