documentcloud/underscore — pull request #669 by politician (2012-07-11 15:59:04+00:00)
Title: Add _.soak for safe navigation - similar to CoffeeScript's `?.` operator

Add _.soak for safe navigation through a chain of properties and functions. If the sequence is broken by null or undefined, _.soak returns undefined; otherwise, returns the value of the sequence.

```JavaScript
var sample1 = {a: {b: function() { return void 0; }}};
sample1.a.b().c; // => throws TypeError
_.soak(sample1, 'a', 'b', 'c'); // => undefined
```
`soak` will pass arguments to functions:

```JavaScript
var sample2 = {a: {b: function(x,y) { return x === 2 ? void 0 : x+y; }}};
sample2.a.b(2,3).toString() || false; // => throws TypeError
_.soak(sample2, 'a', ['b',2,3], 'toString') || false; // => false
```
`soak` takes the following syntax:

```
_.soak(object, 'a', 'b', ['fn', 1, 2]); // arguments
_.soak(object, ['a', 'b', ['fn', 1, 2]]); // vector
```