Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es6-weak-map

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es6-weak-map

ECMAScript6 WeakMap polyfill

  • 2.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.6M
decreased by-6.11%
Maintainers
1
Weekly downloads
 
Created

What is es6-weak-map?

The es6-weak-map npm package provides a polyfill for the ES6 WeakMap implementation. It allows for the creation of collections of key/value pairs where the keys are objects and the values can be arbitrary values. The key feature of WeakMaps is that they do not prevent garbage collection if there are no other references to the key object, making them useful for managing memory in large applications.

What are es6-weak-map's main functionalities?

Creating and using a WeakMap

This code demonstrates how to create a WeakMap, add a key/value pair to it, retrieve the value using the key, and then allow the key to be garbage collected by removing references to it.

{"var WeakMap = require('es6-weak-map');\nvar myWeakMap = new WeakMap();\nvar obj = {};\nmyWeakMap.set(obj, 'value');\nconsole.log(myWeakMap.get(obj)); // 'value'\nobj = null; // Now obj can be garbage collected if no other references exist"}

Checking for a key's presence and deleting a key

This example shows how to check if a WeakMap contains a certain key using the `has` method and how to remove a key/value pair from the WeakMap using the `delete` method.

{"var WeakMap = require('es6-weak-map');\nvar myWeakMap = new WeakMap();\nvar obj = {};\nmyWeakMap.set(obj, 'value');\nconsole.log(myWeakMap.has(obj)); // true\nmyWeakMap.delete(obj);\nconsole.log(myWeakMap.has(obj)); // false"}

Other packages similar to es6-weak-map

Keywords

FAQs

Package last updated on 07 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc