Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

emptyfunction

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emptyfunction

An empty function.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
230
decreased by-41.48%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 16 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc