Skip to content

ES6学习笔记之WeakMap和WeakSet #3

@JuneDeng2014

Description

@JuneDeng2014

WeakMapWeakSet

WeakMapWeakSetMapSet类似,但限制更少:

  • WeakMap只支持new,.has(),.get(),.set(),.delete()
  • WeakSet只支持new,.has(),.add(),.delete()
  • WeakSet的值和WeakMap的键必须是对象。

WeakMapWeakSet都不能迭代。
只能传入具体的键获取弱集合的条目。

这些精心设计的限制让垃圾回收器收集dead objects out of live weak collections(不知道怎么翻译)。

原文:https://hacks.mozilla.org/2015/06/es6-in-depth-collections/

Metadata

Metadata

Assignees

No one assigned

    Labels

    ES6my learn notes on es6

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions