canonical
Version:
Canonical code style linter and formatter for JavaScript, SCSS and CSS.
55 lines (30 loc) • 911 B
Markdown
> Only call a function once
When called multiple times it will return the return value from the first call.
*Unlike the module [once](https://github.com/isaacs/once), this one isn't naughty extending `Function.prototype`.*
```sh
$ npm install --save onetime
```
```js
var i = 0;
var foo = onetime(function () {
return i++;
});
foo(); //=> 0
foo(); //=> 0
foo(); //=> 0
```
Type: `function`
Function that should only be called once.
Type: `boolean`
Default: `false`

Set to `true` if you want it to fail with a nice and descriptive error when called more than once.
MIT © [Sindre Sorhus](http://sindresorhus.com)