Expression closures - use-cases for shortcut lambda syntax (blocks)
Bob Ippolito
bob at redivi.com
Sat Mar 17 12:57:58 PDT 2007
On 3/17/07, Bob Ippolito <bob at redivi.com> wrote:
> On 3/17/07, Vassily Gavrilyak <gavrilyak at gmail.com> wrote:
> > > addLoadEvent(function(){
> > > connect('bad_example','onclick', \(e) signal('bad_example'));
> > > connect('bad_example','showvalue',window,'alert');
> > >
> > > connect('good_example','onclick', \(e) signal(randomObj));
> > > connect(randomObj,'showvalue',window,'alert');
> > > });
> > >
> >
> > Actually it should be this, with operator, functions expressions,
> > types and lambda
> >
> > addLoadEvent(function(){
> > bad_example.onclick += (\ _) bad_example.showvalue("explicit_value");
> > bad_example.showvalue += (\ s:String) window.alert(s);
> > good_example.onclick += (\ _) randomObj.showvalue("explicit_value");
> > randomObj.showvalue += (\ s:String) window.alert(s);
> > });
> >
> > Now it's cleared from all the syntactic noise.
> > Signal-slot framework in ES is something strange that should not be here at all.
> > ES object properties are slots and functions calls are signals.
> > Connection should be an assignment. ES is not C++, there is no needs
> > for workarounds
> > Thats the first thing bad with this example.
> > Second thing is that is uses method names in order to actually shorten
> > up code (avoid writing 'function' directly).
> > With operators, expression closures and lambdas there will be no place
> > left for such framework. Everything would be possible to write
> > directly and use typing and compilation niceties.
>
> 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.
Additionally the method names are used because it's shorthand for:
function (object, method) { return function () { return
object[method].apply(object, arguments); }; };
Really...
-bob
More information about the Es4-discuss
mailing list