Reiterate 1.2: operators are (kind of) methods now!

You know how, in Ruby, + is a method? Well guess what:

// Count members within a range
numbers.findAll({'>': 4, '<=': 27}).length

// Remove items of a specific type
collection.reject(['instanceof', String])

// Assign default values to a collection
[27, 0, 'prototype', '', true, false].map({'||': 'foo'})
// -> [27, "foo", "prototype", "foo", true, "foo"]

How’s about that then?

If you’ve enjoyed this article, you might enjoy my recently published book JavaScript Testing Recipes. It’s full of simple techniques for writing modular, maintainable JavaScript apps in the browser and on the server.