# @kt3k/proto-polyfill

> Provide __proto__ with some limitations

Latest version **1.0.0** (published 2021-03-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kt3k/proto-polyfill
pnpm add @kt3k/proto-polyfill
yarn add @kt3k/proto-polyfill
bun add @kt3k/proto-polyfill
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-03-10 |
| First published | 2021-03-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yoshiya Hinosawa |
| Maintainers | kt3k |
| Keywords | proto, static, class, es6, polyfill, ie9, ie10, babel, webpack |

## Links

- npm: https://www.npmjs.com/package/@kt3k/proto-polyfill
- Repository: https://github.com/kt3k/proto-polyfill
- Homepage: https://github.com/kt3k/proto-polyfill#readme
- Issues: https://github.com/kt3k/proto-polyfill/issues
- npm.io page: https://npm.io/package/@kt3k/proto-polyfill

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2021-03-10

## README

# proto-polyfill &middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/webcarrot/proto-polyfill/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/proto-polyfill.svg?style=flat)](https://www.npmjs.com/package/proto-polyfill)

Provide `__proto__` with some limitations

## browsers that need this polyfill

In general old browsers that **not** provide legacy `__proto__` and **support** `Object.defineProperty`, `Object.getPrototypeOf`, `Object.getOwnPropertyNames`, `Object.getOwnPropertyDescriptor` and `Object.create`:

- IE 9
- IE 10

IE 8 is **not** supported.

### why and when

If you do things like:
./tests/class-like.js
or (ES6 version):

```js
class X {
  static get foo() {
    return "xFoo";
  }
  get foo() {
    return this.constructor.foo + " by instance!";
  }
}
X.s = { s: "x" };
X.f = "X";
class Y extends X {
  static get foo() {
    return this.__proto__.foo + " > yFoo";
  }
}
Y.s = {
  s: "y"
};
Y.f = "Y";
class Z extends Y {
  static get foo() {
    return this.__proto__.foo + " > zFoo";
  }
  get foo() {
    return "My special Z foo " + super.foo;
  }
}
Z.f = "Z";
var x = new X();
var y = new Y();
var z = new Z();
console.log(x.foo); // xFoo by instance!
console.log(y.foo); // xFoo > yFoo by instance!
console.log(z.foo); // My special Z foo xFoo > yFoo > zFoo by instance!
console.log(x.constructor.s.s); // x
console.log(x.constructor.f); // X
console.log(y.constructor.s.s); // y
console.log(y.constructor.f); // Y
console.log(z.constructor.s.s); // y
console.log(z.constructor.f); // Z
```

...and code produced by compliler ( babel 6.x ) not work properly in old browsers like ie9-10.

## installation

`npm install --save-dev proto-polyfill`

And use like polyfill...

## limitations

Look at ./tests/limitations.js

```js
var x = {
  a: "xa"
};
function X() {}
X.prototype.a = "Xa";
X.prototype.cv = "XCV";
X.prototype.ab = function() {
  return "ab:" + this.a;
};
Object.defineProperty(X.prototype, "c", {
  get: function() {
    return this.ab() + ":" + this.cv;
  }
});
// no way to replace object prototype "in place" ?
x.__proto__ = X.prototype;
console.log(x instanceof X); // invalid log: false should true
// but some kind emulation works
console.log(x.a); // ok log: "xa";
console.log(x.ab()); // ok log: "ab:xa";
console.log(x.c); // ok log: "ab:xa:XCV";
// normal instance
var iX = new X();
console.log(iX instanceof X); // ok log: true
console.log(iX.a); // ok log: "Xa";
console.log(iX.ab()); // ok log: "ab:Xa";
console.log(iX.c); // ok log: "ab:Xa:XCV";
// override
X.prototype.cv = "XCV2";
console.log(x.c); // ok log: "ab:xa:XCV2";
x.cv = "XCV3";
console.log(x.c); // ok log: "ab:xa:XCV3";
// but
X.prototype.newProp = "newProp";
console.log(x.newProp); // invalid log: undefined should "newProp";
```

### Pseudo Symbol()

Pseudo `Symbol()` props are skipped (core-js Set polyfill use it)

### Object.setPrototypeOf

Only emultation

### Object.getPrototypeOf

Override to make super() work in Babel 7

## tests

`./tests/index.html`

PR welcome.

---
_Source: https://npm.io/package/@kt3k/proto-polyfill · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
