RegExps in array functions
reichsteinatwork at gmail.com
Sat Mar 24 04:06:31 PDT 2012
On Sat, Mar 24, 2012 at 5:54 AM, Brandon Benvie
<brandon at brandonbenvie.com> wrote:
> I've been struggling for a way to describe this idea, but it's almost like
> we're lacking what amounts to a "valueOf" where the expected result is a
> callable. The regex-as-filter is a good example of that use case. You don't
> want the base object to be a function or callable necessarily, but you do
> want to indicate that there's a clear callable representative of the object.
The problem is that there are so many ways you might want to use an
object as a function, not just one. In this case, we want it as a
predicate. In other cases you might want it to return the match as a
string, or as a match. Or you want your generic objects to match
against different properties.
The use-case here is that you have an object and want it to act as a
function in a specific case, and it's driven by the way the object is
used, which is unbounded, not the way the object is defined. You can't
be expected to predict all the ways an object is going to be used, and
create one function representation suiting the all.
For this, you need a function per usage, so the "predicate" function
suggested above is exactly the right level of abstraction.
More information about the es-discuss