three small proposals: the bikeshed cometh!

Alex Russell alex at dojotoolkit.org
Thu Apr 29 04:23:13 PDT 2010


On Thu, Apr 29, 2010 at 4:15 AM, Mike Shaver <mike.shaver at gmail.com> wrote:
> On Thu, Apr 29, 2010 at 3:25 AM, Alex Russell <alex at dojotoolkit.org> wrote:
>> 3.) Syntax for bound function de-reference
>>
>> Many functions, both in the DOM and in the library, accept functions as
>> arguments. ES5 provides a bind() method that can ease the use of these
>> functions when the passed method comes from an object. This is, however,
>> inconvenient. E.g.:
>>
>>  node.addEventListener("click", obj.method.bind(obj, ...));
>
> node.addEventListener("click", #(e){obj.method(e)});

...which i then can't get a reference to for disconnection. But point taken.

>>  1.) all de-references via bang from an object/function pair return the
>> *same* function object (modulo #4).
>>  2.) non-function objects de-referenced via bang are not mangled in any way
>> (identical to dot-operator de-reference)
>>  3.) there's no provision for binding arguments (curry)
>>  4.) bang-bound functions are weakly referenced. If GC would otherwise
>> remove a function object from memory, having previously bang-bound a
>> function should not keep the function object alive
>
> I'm not sure how you make 1 and 4 happen at the same time.

That's the weakref bit. If GC happens and the only thing with a handle
is the internal bang binding, the generated function object should be
released. If something else holds onto it strongly and you ask for the
bang-bound variant again, it should return the object that was
returned previously.

> (It also
> sounds like you're saying that bang-bound functions weakly reference
> their inner function, not that they are themselves weakly referenced.)

Yeah, sorry for not being clear.

Regards


More information about the es-discuss mailing list