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

partial-apply

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

partial-apply

Call a function using an array of arguments while maintaining its original "this" context.

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

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

partial-apply

Implements a context-free version of Function.prototype.apply in Node.js/JavaScript.

If someFn has unknown arguments, and we want to pass those arguments through to a wrapped function, say someOtherFn, we can use someOtherFn.apply() to call the wrapped function with someFn's arguments.

But in the process, we corrupt the "this" context of the wrapped function. In order to have it stay correctly defined, we have to pass in the context manually. This creates some nasty dependencies and hurts reusability in your code base.

_.partial() in lodash gets us a bit closer, but it does not support an array of arguments- just arguments passed in one after the other, like _.partial(fn,x0,x1,etc).

For example, if we expected someOtherFn in the example below to have its "this" value refer to, say, a Waterline model, it's actually quite annoying in vanilla JavaScript to pass down a dynamic array of arguments to a function AND maintain its original "this" context.

Anyway, this is why partial-apply was created.

Installation

$ npm install partial-apply

Usage

var partialApply = require('partial-apply');

function someFn( /* ... */ ) {
  return partialApply(someOtherFn, arguments);
}

Why?

This module is a temporary solution, until lodash has something similar in core that can be called as a single method. In the mean time, this is a hack to make our code more readable.

To get the latest status, see the lodash docs.

I'll update this repo with install/version info if something comparable is added to lodash core at some point.

License

MIT © Mike McNeil 2014

Keywords

FAQs

Package last updated on 31 May 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

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