🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
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

Simply an empty closure.

0.0.0
Source
npm
Version published
Maintainers
1
Created
Source

emptyFunction (NodeJS)

Nothing but an empty function closure.

Primarily Intended for optional closures. This allows you to use one empty closure object in your entire project, and whenever you need it, you can just pass it by reference instead of creating a new closure.

install

npm install emptyfunction

usage

Get the closure from the module

var emptyFunction = require('emptyfunction');

Whenever there's an optional closure, just add the empty function if no closure is provided

function MyClass(closureArgument) {
    if (typeof closureArgument === "function") {
        this.someFunction = closureArgument
    } else {
        this.someFunction = emptyFunction;
    }
}

Write your class as if the function exists

MyClass.prototype.doSomething = function() {
    this.someFunction();
}

identifying

Sometimes you might need to verify if the closure is an empty function.

If you're inside the same package you can use:

this.someFunction === emptyFunction

If not, a more hacky solution is to use:

this.someFunction.name === 'emptyFunction'

Keywords

empty

FAQs

Package last updated on 01 Jun 2014

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