On Sep 28, 3:44 am, Jim Higson <j...@wikizzle.org> wrote:
> On Saturday 26 September 2009 04:04:22 kangax wrote:
>
>
>
> > On Sep 24, 11:20 pm, Andrew Dupont <goo...@andrewdupont.net> wrote:
> > > Unless anyone has serious objections, or has a better idea, I'm going
> > > to add these as aliases of `Prototype.emptyFunction` and
> > > `Prototype.K`, respectively. They belong better there, since in theory
> > > the `Prototype` namespace is for internal stuff, not for stuff that
> > > has value to end-user developers.
>
> > It sure makes more sense to have those on `Function`. I kind of hate
> > that we're putting yet another (completely made-up) method on yet
> > another built-in native, but it looks like there's not much that can
> > be done about it at this point anyway.
>
> > As far as naming, I would probably go with `Function.empty` and
> > `Function.identity` (`Function.K` looks neat but it would then make
> > sense to uppercase `EMPTY` too, and I like lowercase version more).
>
> > Now that we're on this subject, we can also add so often useful
> > `Function.false` (i.e. `function(){ return false; }`). I use it all
> > the time for things like preventing events -
> > `someElement.onselectstart = Prototype.falseFunction;`, etc.
>
> > Is anyone else using something like that?
>
> I have Function.alwaysReturn( val );
>
> So, I'd use Function.alwaysReturn( false ) in that case.
>
> Is good for anywhere a function is expected but you want to insert a value.
> Eg, Function.alwaysReturn( 4 );
>
> Function.alwaysReturn =
>         function ( val ){
>                 return (function(){return val});
>         };

I remember seeing this in Dean's base2.js and Oliver Steele's
functional.js under then name - "K":

function K(value){
  return function() {
    return value;
  }
}

It's then easy to define other abstractions with this one function -

Function.empty = K();
Function.false = K(false);
Function.true = K(true);

// etc.

--
kangax
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to