lodash/lodash — pull request #525 by traviskaufman (2014-04-13 16:57:52+00:00)
Title: Add `_.iife` for immediately invoking functions.

`_.iife` takes a function as its first argument and calls it immediately,
passing in any additional specified arguments to the function, and then returns
the value of whatever was returned from the called function. This is useful as a
semantic wrapper for IIFE's and/or mocking out asynchronous task-based functions
in tests, such as `setTimeout`.

#### Some background
On the Refinery29 mobile web team we like to stub out `setTimeout` in some of our tests and simply have it call the function given to it. We find that this reduces test complexity when the code under question is not dependent on that asynchronous behavior, and it also speeds up our suite by quite a lot. The way we usually go about this is by doing something like

```javascript
spyOn(window, 'setTimeout').and.callFake(function(fn) { fn(); });
```

But this looks ugly and get cumbersome to type. We wanted to be able to pass in a higher-order function that could be used as a default "call whatever your first argument is if it's callable" behavior (in the same way that `_.identity` provides a convenient iterator), and couldn't find a library function in lodash that did this. So rather than write it ourselves and have it never see the light of day, I thought that it could be a useful addition to lodash's utility function.

Beyond just providing the utility described above, `_.iife` could also possibly be used in the classic IIFE way
```javascript
_.iife(function(global) {
// your module here
}, this);
```
To provide a more semantic indication of an IIFE than just `(function() { ... })();` which - while canonical - could stand to be more denotative of what it's actually doing. This is why I made the function be able to accept arguments.

Thank you very much for creating and maintaining lodash! It's an awesome library that we all love using.