I really need to know why WeakMaps don't accept primitives as keys, can anyone 
please reply ? 

Thanks!
--
Irakli Gozalishvili
Web: http://www.jeditoolkit.com/
Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu)


On Thursday, 2011-11-10 at 10:31 , Irakli Gozalishvili wrote:

> Hi, 
> 
> I was wondering what is a reason for disallowing non-object values as keys in 
> WeakMaps ?
> 
> Also, I think I have a pretty good use case for primitive keys:
> 
> Worker process sends messages to the (main) UI process, to initiate UI 
> notification. If user clicks that notification main process will worker know 
> that given notification was clicked:
> 
> (function(exports) {
> 
> let id = 0
> let listeners = WeakMap()
> 
> exports.notify = function notify({ onClick, message }) {
>   if (onClick) listeners.set(++id, onClick)
>   self.postMessage({ id: id, message: message })
> }
> 
> self.onmessage = function({ id }) {
>   let listener = listeners.get(id)
>   if (listener) listener()
> }
> 
> })(this)
> 
> Is my use case invalid ? At the moment I use custom map implementation with a 
> limited size, once map hits the limit oldest entries will be removed. 
> 
> Regards
> --
> Irakli Gozalishvili
> Web: http://www.jeditoolkit.com/
> Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu)
> 

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to