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):
static { return "xFoo"; } { return thisconstructorfoo + " by instance!"; }Xs = s: "x" ;Xf = "X"; static { return this__proto__foo + " > yFoo"; }Ys = s: "y";Yf = "Y"; static { return this__proto__foo + " > zFoo"; } { return "My special Z foo " + superfoo; }Zf = "Z";var x = ;var y = ;var z = ;console; // xFoo by instance!console; // xFoo > yFoo by instance!console; // My special Z foo xFoo > yFoo > zFoo by instance!console; // xconsole; // Xconsole; // yconsole; // Yconsole; // yconsole; // 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
var x = a: "xa"; {}Xprototypea = "Xa";Xprototypecv = "XCV";Xprototype { return "ab:" + thisa;};Object;// no way to replace object prototype "in place" ?x__proto__ = Xprototype;console; // invalid log: false should true// but some kind emulation worksconsole; // ok log: "xa";console; // ok log: "ab:xa";console; // ok log: "ab:xa:XCV";// normal instancevar iX = ;console; // ok log: trueconsole; // ok log: "Xa";console; // ok log: "ab:Xa";console; // ok log: "ab:Xa:XCV";// overrideXprototypecv = "XCV2";console; // ok log: "ab:xa:XCV2";xcv = "XCV3";console; // ok log: "ab:xa:XCV3";// butXprototypenewProp = "newProp";console; // 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.