On Mar 23, 2012, at 9:05 PM, John Tamplin <[email protected]> wrote:
> On Fri, Mar 23, 2012 at 8:21 PM, Domenic Denicola > <[email protected]> wrote: > Does passing /foo/i.test not work? (Away from computer.) Perhaps it should, > if it doesn't? > > It does, if you bind it to the regex first. Ie: > > var re = /foo/i; > var filtered = array.filter(re.test.bind(re)); > > So that doesn't look better than just passing an anonymous function wrapper > (though you probably want to build the regex once). Yeah, gotta watch your receiver. If you find yourself doing this a lot, just make a function. You can either add a method to RegExp that returns a bound version of test, or make a function that takes a regex and returns a bound version of test like function predicate(regex){ return regex.test.bind(regex); } var filtered = array.filter(predicate(/foo/i)); - Russ > > -- > John A. Tamplin > Software Engineer (GWT), Google > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

