New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

defer-calls

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defer-calls

Defer calls to an object's method, then executes them all when you give the signal

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

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

Defer calls

Defer calls to an object's method, then executes them all when you give the signal

Install

npm i defer-calls

Use

var deferMethod = require('defer-calls').method;

var guy = {
  sayHello: function(name) {
    return 'Hello ' + name;
  }
};

guy.sayHello('you'); // => 'Hello you'

var helloWaiting = deferMethod(guy, 'sayHello', function (name) {
  return 'Wait ' + name;
});
// The 3rd arg is the temporary behavior, if you just want to return a value,
// you can pass this value instead of a function.

// Hold it...
guy.sayHello('world'); // => 'Wait world'
guy.sayHello('everyone'); // => 'Wait everyone'

helloWaiting.callsList; // => [['world'], ['everyone']];
// WARNING : ['world'] and ['everyone'] are "arguments arrays" i.e. not real Arrays
// See here : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Fonctions/arguments

// Then give the signal!
helloWaiting.execAll() // => ['Hello world', 'Hello everyone']

// After that...
helloWaiting.execAll(); // Noop
helloWaiting.callsList; // []

// Everything is back to normal
guy.sayHello('Kitty'); // => 'Hello Kitty'

TODO

Equivalent for a function instead of a method.

LICENCE

MIT

Keywords

FAQs

Package last updated on 11 Jun 2015

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