{"action":"created","issue":{"url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/362","repository_url":"https://api.github.com/repos/ruanyf/es6tutorial","labels_url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/362/labels{/name}","comments_url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/362/comments","events_url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/362/events","html_url":"https://github.com/ruanyf/es6tutorial/issues/362","id":218062820,"number":362,"title":"关于WeakMap的一个问题","user":{"login":"vtxf","id":13550568,"avatar_url":"https://avatars1.githubusercontent.com/u/13550568?v=3","gravatar_id":"","url":"https://api.github.com/users/vtxf","html_url":"https://github.com/vtxf","followers_url":"https://api.github.com/users/vtxf/followers","following_url":"https://api.github.com/users/vtxf/following{/other_user}","gists_url":"https://api.github.com/users/vtxf/gists{/gist_id}","starred_url":"https://api.github.com/users/vtxf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vtxf/subscriptions","organizations_url":"https://api.github.com/users/vtxf/orgs","repos_url":"https://api.github.com/users/vtxf/repos","events_url":"https://api.github.com/users/vtxf/events{/privacy}","received_events_url":"https://api.github.com/users/vtxf/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-03-30T02:26:01Z","updated_at":"2017-04-03T04:57:23Z","closed_at":"2017-03-30T11:37:59Z","body":"阮老师，你好！\r\n打扰，问您一个问题。\r\n\r\nSet 和 Map 数据结构一节讲到的 WeakMap 有这样一段代码：\r\n```\r\nvar wm = new WeakMap();\r\nvar element = document.querySelector(\".element\");\r\n\r\nwm.set(element, \"Original\");\r\nwm.get(element) // \"Original\"\r\n\r\nelement.parentNode.removeChild(element);\r\nelement = null;\r\nwm.get(element) // undefined\r\n```\r\n这个里面的这两句：\r\n```\r\nelement = null;\r\nwm.get(element) // undefined\r\n```\r\n是否可以理解为 wm.get(null)，这样的话，貌似就和element没有关系了吧？\r\n我是觉得wm.get(element)并没有办法来检测wm中是否存在没有赋值为null之前的element元素。不知是否有误？\r\n\r\n我在chrome控制台上做了如下测试：\r\n![image](https://cloud.githubusercontent.com/assets/13550568/24484990/ef10141a-1533-11e7-9b59-43a720d9284b.png)\r\n即使有另外一个变量alias引用了element，最后的结果也还是undefined。\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/comments/291048809","html_url":"https://github.com/ruanyf/es6tutorial/issues/362#issuecomment-291048809","issue_url":"https://api.github.com/repos/ruanyf/es6tutorial/issues/362","id":291048809,"user":{"login":"zhliner","id":2814039,"avatar_url":"https://avatars3.githubusercontent.com/u/2814039?v=3","gravatar_id":"","url":"https://api.github.com/users/zhliner","html_url":"https://github.com/zhliner","followers_url":"https://api.github.com/users/zhliner/followers","following_url":"https://api.github.com/users/zhliner/following{/other_user}","gists_url":"https://api.github.com/users/zhliner/gists{/gist_id}","starred_url":"https://api.github.com/users/zhliner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhliner/subscriptions","organizations_url":"https://api.github.com/users/zhliner/orgs","repos_url":"https://api.github.com/users/zhliner/repos","events_url":"https://api.github.com/users/zhliner/events{/privacy}","received_events_url":"https://api.github.com/users/zhliner/received_events","type":"User","site_admin":false},"created_at":"2017-04-03T04:57:23Z","updated_at":"2017-04-03T04:57:23Z","body":"貌似wm的机制就是无法检查是否已经释放掉，因为一旦检查就需要引用待检查值，而这个引用必然是有效的。。。因此值肯定不会销毁。\r\n\r\n曾经尝试过检测……但终于想通了。。。\r\n\r\n> 在 2017年3月30日，下午7:38，Ruan YiFeng <notifications@github.com> 写道：\r\n> \r\n> 我举的这个例子不好。原意是销毁一个对象，导致它自动在wm之中消失，但是实际上造成了wm.get(null)的效果。\r\n> \r\n> 我一时想不出来其他销毁对象的例子，欢迎你帮忙一起想。\r\n> \r\n> —\r\n> You are receiving this because you are subscribed to this thread.\r\n> Reply to this email directly, view it on GitHub <https://github.com/ruanyf/es6tutorial/issues/362#issuecomment-290385234>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ACrwV-4WrMVqYZqBTE7VGWr_GzzDGeATks5rq5QagaJpZM4MtyTL>.\r\n> \r\n\r\n"}}
{"actor":{"display_login":"zhliner"}}