[d565449] | 1 | # has-proto <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
---|
| 2 |
|
---|
| 3 | [![github actions][actions-image]][actions-url]
|
---|
| 4 | [![coverage][codecov-image]][codecov-url]
|
---|
| 5 | [![License][license-image]][license-url]
|
---|
| 6 | [![Downloads][downloads-image]][downloads-url]
|
---|
| 7 |
|
---|
| 8 | [![npm badge][npm-badge-png]][package-url]
|
---|
| 9 |
|
---|
| 10 | Does this environment have the ability to set the [[Prototype]] of an object on creation with `__proto__`?
|
---|
| 11 |
|
---|
| 12 | ## Example
|
---|
| 13 |
|
---|
| 14 | ```js
|
---|
| 15 | var hasProto = require('has-proto');
|
---|
| 16 | var assert = require('assert');
|
---|
| 17 |
|
---|
| 18 | assert.equal(typeof hasProto(), 'boolean');
|
---|
[79a0317] | 19 |
|
---|
| 20 | var hasProtoAccessor = require('has-proto/accessor')();
|
---|
| 21 | if (hasProtoAccessor) {
|
---|
| 22 | assert.equal([].__proto__, Array.prototype);
|
---|
| 23 | } else {
|
---|
| 24 | assert(!('__proto__' in Object.prototype));
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | var hasProtoMutator = require('has-proto/mutator');
|
---|
| 28 | var obj = {};
|
---|
| 29 | assert('toString' in obj);
|
---|
| 30 |
|
---|
| 31 | obj.__proto__ = null;
|
---|
| 32 | if (hasProtoMutator) {
|
---|
| 33 | assert(!('toString' in obj));
|
---|
| 34 | } else {
|
---|
| 35 | assert('toString' in obj);
|
---|
| 36 | assert.equal(obj.__proto__, null);
|
---|
| 37 | }
|
---|
[d565449] | 38 | ```
|
---|
| 39 |
|
---|
| 40 | ## Tests
|
---|
| 41 | Simply clone the repo, `npm install`, and run `npm test`
|
---|
| 42 |
|
---|
| 43 | [package-url]: https://npmjs.org/package/has-proto
|
---|
| 44 | [npm-version-svg]: https://versionbadg.es/inspect-js/has-proto.svg
|
---|
| 45 | [deps-svg]: https://david-dm.org/inspect-js/has-proto.svg
|
---|
| 46 | [deps-url]: https://david-dm.org/inspect-js/has-proto
|
---|
| 47 | [dev-deps-svg]: https://david-dm.org/inspect-js/has-proto/dev-status.svg
|
---|
| 48 | [dev-deps-url]: https://david-dm.org/inspect-js/has-proto#info=devDependencies
|
---|
| 49 | [npm-badge-png]: https://nodei.co/npm/has-proto.png?downloads=true&stars=true
|
---|
| 50 | [license-image]: https://img.shields.io/npm/l/has-proto.svg
|
---|
| 51 | [license-url]: LICENSE
|
---|
| 52 | [downloads-image]: https://img.shields.io/npm/dm/has-proto.svg
|
---|
| 53 | [downloads-url]: https://npm-stat.com/charts.html?package=has-proto
|
---|
| 54 | [codecov-image]: https://codecov.io/gh/inspect-js/has-proto/branch/main/graphs/badge.svg
|
---|
| 55 | [codecov-url]: https://app.codecov.io/gh/inspect-js/has-proto/
|
---|
| 56 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/has-proto
|
---|
| 57 | [actions-url]: https://github.com/inspect-js/has-proto/actions
|
---|