jashkenas/underscore — pull request #1518 by mehdishojaei (2014-03-11 13:18:45+00:00)
Title: Optimize _.contains for performance

Currently surprisingly `_.contains` is slower than `_.indexOf`, see [this](http://jsperf.com/contains-vs-indexof-on-arrays), this PR improved the performance of `_.contains`. see it [here](http://jsperf.com/improve-contains).

This can improve the performance of any function that uses that, currently: `_.uniq`, `_.intersection`, `_.difference` and `_.omit`.

The amazing thing is that, this can improve performance of `_.contains` even when it called with arrays on modern browsers. While we know that when `_.contains` called on arrays, this method uses the `indexOf` of the array and the execution path never reach to the function `any`.

This change increases the ease of access to the closure variable `target` by passing it as context of the callback function.