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

bind-late

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bind-late

Late binding of overridable object properties.

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

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

bind-late npm version

Late binding of overridable object properties.

Description

Define an overridable object where special "late binded" functions will be treated as lazy memoized properties.

All the functions in the object structure that are anonymous and take a single _ argument, are considered to be "late bindings". When the property is accessed the first time, they are called with the final overridden object as _ parameter, and their return value is affected to the property.

Nesting

You can nest late binded objects. Late binded objects are not plain objects and will not be recursively extended during an override, so you need to extend them explicitely (this is often what you want, since override would otherwise just copy your properties and not rebuild the inner late binded object according to what you changed).

Example

const bindLate = require('bind-late')

const a = bindLate({
  a: 8,
  b: {
    c: 2,
    d: _ => _.a + _.b.c,
  },
  e: _ => _.b.d * 2,
})

a.b.d === 10 // 8 + 2
a.e === 20 // 10 * 2

const b = a.override({ a: 6 })

b.b.d === 8 // 6 + 2
b.e === 16 // 8 * 2

const c = b.override({
  b: { c: 6 },
  e: _ => _.b.d - 2,
})

c.b.d === 12 // 6 + 6
c.e === 10 // 12 - 2

You can also watch the antisocial-auth source code for a more concrete example, where everything is overridable thanks to bind-late.

Demo

See the demo directory to see a functional example you can tweak and play with.

Keywords

FAQs

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