I just realized that you may pass a second argument to the array methods. So instead of passing an regular expression as the first argument, you may just pass the test method as the first and the regular expression as the second argument. It's then used as the test method's `this` argument. When the function is cached, this method is (in the shortest case) two characters longer than passing a RegExp directly. This way, it's probably as fast as it can get.
It seems like somebody thought about this use case when adding the second argument. It's also possible to use other methods - Object.prototype.hasOwnProperty is a great candidate. Invokable RegExps would have been a solution, although nobody would expect a RegExp to be invokable (because it's pretty exotic) and it probably wouldn't have been used anyways by a lot of people.
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

