Skip to content

Smarter binding of function with some context. It uses .apply instead of .bind, with reason.

License

Notifications You must be signed in to change notification settings

tunnckoCore/smart-bind

Smarter binding of function with some context. It uses .apply instead of .bind, with reason.

code climate standard code style travis build status coverage status dependency status

Install

npm i smart-bind --save

Usage

For more use-cases see the tests

const smartBind = require('smart-bind')

Smart bind ctx to fn instead use of native .bind

Params

  • ctx {Object|Function}
  • fn {Function}
  • returns {Function}

Example

var smartBind = require('smart-bind')

function zoopark () { return this.foo }

var bound = smartBind({foo: 'bar'}, zoopark)

console.log(bound()) // => 'bar'
console.log(bound.toString()) // => 'function zoopark () { return this.foo }'

Related

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

About

Smarter binding of function with some context. It uses .apply instead of .bind, with reason.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •