documentcloud/underscore — Issue #331: let know if _.once'd function was already ran
Author: thesebas
Created: 2011-10-14 18:36:55+00:00
State: open

I would like to know if `_.once'd` function was run for the first time or it returns memoized results, something like:

```javascript
_.once = function(func) {
var memo, f;
f = function() {
if (f.ran) return memo;
f.ran = true;
return memo = func.apply(this, arguments);
};
return f;
};
```

and then:

```javascript
func = function () {
console.log('execution!');
return 42;
}

onced = _.once(func);

console.log(!onced.ran?'first':'next');
// >> first
console.log(onced());
// >> execution!
// = 42
console.log(!onced.ran?'first':'next');
// >> next
console.log(onced());
// = 42
console.log(!onced.ran?'first':'next');
// >> next
```