On Thu, May 12, 2011 at 4:29 PM, David Bruant <[email protected]> wrote:
> Le 13/05/2011 01:19, Mike Samuel a écrit : > > 2011/5/11 David Bruant <[email protected]>: > >> Hi, > >> > >> I've recently been thinking about the case of memoizing. Let's assume > that a > >> function f takes an object o as a parameter and that f is a pure > function > >> (results only depends on argument). > >> ---- > >> function f(o){ > >> /* perform a computation, return the result */ > >> } > >> ---- > >> > >> A memoizer could be written to improve f time performance (by the cost > of > >> memory, of course). > >> ---- > >> function memoizer(f){ > >> var cache = WeakMap(); > >> return function(o){ > >> var res; > >> if(WeakMap.has(o)) > >> return cache.get(o); > >> res = f.apply(this, o); > >> > >> cache.set(o, res); > >> }; > >> } > > Does this do what you were trying to accomplish with has, but without > > requiring has? > Yes, I'm sorry, I shouldn't have used the word "require". > Your example does work. It is some derivation of what can be found at > > http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps&s=weakmap#explicit_soft_own_fields > I get that neither "has" nor "delete" are required, as proves the above > link and your example. Still, I'm confident that the engine would be a > better place to handle it and my point was that there are some use cases > that may do "heavy" usage of a ".has" method on weak maps which in my > opinion is an argument in favor of adding "has" in the WeakMap API. > It turns out, it seems to already be the plan as wrote Mark Miller in a > previous e-mail. The wiki just cannot be updated yet, before consensus > is reached during a TC-39 meeting. > I am planning to update the wiki to reflect what I expect to propose in July[1], which includes "has", but I won't get to it till well after the May meeting. When I do get to it, I will revisit this thread, so don't wait on my updates to discuss this here. [1] Which is approx what Andreas Gal already implemented and is shipping in FF6.0a1 Nightly. > > David > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > -- Cheers, --MarkM
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

