Expression closures - use-cases for shortcut lambda syntax (blocks)

Bob Ippolito bob at
Sat Mar 17 13:58:55 PDT 2007

On 3/17/07, Vassily Gavrilyak <gavrilyak at> wrote:
> On 3/17/07, Bob Ippolito <bob at> wrote:
> > > The signal/slot implementation in MochiKit is not at all superfluous.
> > > More than one callback can be connected to a slot, and when connected
> > > to DOM objects it presents a uniform event object regardless of the
> > > underlying implementation.
> > >
> > > No needs for workarounds? Are you kidding? We are talking about web browsers.
> I am not criticizing Mochikit, I like it. It covers many workarounds
> for browsers.
> What I am telling that it shouldn't be here, such framework is
> possible to have in language directly and C# proves this.
> About more then one callback - that's exactly why I used += and not just =.
> Again, that is already solved in C#. And it should be as much simpler
> in ES, otherwise people will just move to C# and use compilers to JS.
> > Additionally the method names are used because it's shorthand for:
> >
> > function (object, method) { return function () { return
> > object[method].apply(object, arguments); }; };
> >
> > Really...
> That's I understand too, and used same approach in my code 2 years
> ago. Then I moved to functions, because methods are not that really
> needed. When I need to pass method to callback expecting function I do
> just setCallback(obj.method.delegate(obj)). This way only one argument
> (function) is needed in API, not two (object, method). Having 2
> arguments complicates API, and built-in callbacks still provides one
> argument only (like setTimeout or Array.sort), so for me
> looks better to stay coherent with such callbacks.
> Also there is no strings usage here, everything looks like it is "typed".
> And direct call is still the best, especially with typed ES4.

The API in question supports either one argument or two, actually. We
ended up supporting both because of syntax economy.

Even if MochiKit did add delegate to Function.prototype you still have
to repeat the object twice. That's no fun. MochiKit.Base.bind(fn,
object) is the same as your Function.prototype.delegate, but people
prefer to use MochiKit.Base.method(obj, methodName) because they don't
have to type as much.

The MochiKit.Signal.connect call in this case allows one or two
arguments to specify the callback directly or object+method as an
implicit call to method(obj, methodName).


More information about the Es4-discuss mailing list