# emptyfunction

> An empty function.

Latest version **1.0.0** (published 2016-06-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install emptyfunction
pnpm add emptyfunction
yarn add emptyfunction
bun add emptyfunction
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-06-16 |
| First published | 2014-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Christophe Bol |
| Maintainers | boljen |
| Keywords | empty, function, closure, callback |

## Links

- npm: https://www.npmjs.com/package/emptyfunction
- Repository: https://github.com/boljen/emptyfunctionjs
- Issues: https://github.com/boljen/emptyfunctionjs/issues
- npm.io page: https://npm.io/package/emptyfunction

## Recent versions

- 1.0.0 (latest) — 2016-06-16
- 0.0.0 — 2014-06-01

## README

# emptyFunction (Javascript)

The module exports nothing but an empty function/closure.

## install

    npm install emptyfunction

## Usage

Get the empty closure from the module

    var emptyFunction = require('emptyfunction');

Now use the function whenever there is an optional closure within your code.

    function example(cb) {
      if (!cb) cb = emptyFunction
      for (var i = 0; i < 1337; i++) cb()
    }

### isEmptyFunction

Sometimes you might need to verify whether the closure is an empty function.

If you have access to the emptyFunction object you can do a strict comparison.

    this.someFunction === emptyFunction

If not, a more hacky solution is to use the name of the function:    

    this.someFunction.name === 'emptyFunction'

### Utilities

A simple function to check whether we're dealing with an actual closure:

    function isClosure(cb) {
      return (cb && cb !== emptyFunction) ? true: false
    }

A simple function to make assigning closures easier:

    function setClosure(cb) {
      return (isClosure(cb)) ? cb : emptyFunction
    }

    // Usage:
    var myClosure = setClosure(cb)

## License

MIT

---
_Source: https://npm.io/package/emptyfunction · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
