9a96b8cf5e7142498057a677c980bae1ba7f2be9d87b8b1563912d96eb093a1fda0b9febe3da75bd7a36d1f6b2f15af915b05d8f028724422f634e0d20af1c 3.7 KB

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