What is weakmap-polyfill?
The weakmap-polyfill npm package provides a polyfill for the WeakMap object, which is a collection of key/value pairs where the keys are objects and the values can be arbitrary values. This polyfill is useful for environments that do not natively support WeakMap.
What are weakmap-polyfill's main functionalities?
Creating a WeakMap
This feature allows you to create a new instance of a WeakMap using the polyfill.
const WeakMapPolyfill = require('weakmap-polyfill');
const wm = new WeakMapPolyfill();
Setting a value
This feature allows you to set a value in the WeakMap for a specific object key.
const obj = {};
wm.set(obj, 'value');
Getting a value
This feature allows you to retrieve a value from the WeakMap using an object key.
const value = wm.get(obj);
Checking for a key
This feature allows you to check if a specific object key exists in the WeakMap.
const hasKey = wm.has(obj);
Deleting a key
This feature allows you to remove a key/value pair from the WeakMap.
wm.delete(obj);
Other packages similar to weakmap-polyfill
core-js
core-js is a modular standard library for JavaScript that includes polyfills for various ECMAScript features, including WeakMap. It provides a comprehensive set of polyfills for modern JavaScript features, making it a more extensive solution compared to weakmap-polyfill.
es6-weak-map
es6-weak-map is another polyfill for the WeakMap object. It provides similar functionality to weakmap-polyfill but is specifically focused on WeakMap, making it a more lightweight alternative to core-js.
weakmap-polyfill
ECMAScript6 WeakMap polyfill.
Installation
Available on npm
as weakmap-polyfill.
$ npm install weakmap-polyfill --save
This can also be installed with Bower
.
$ bower install weakmap-polyfill
WeakMap will defined in the global scope if native WeakMap is not supported.
require('weakmap-polyfill');
var weakMap = new WeakMap();
License
MIT