1.0.1 • Published 8 years ago

is-bound-function v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

is-bound-function npmjs.com The MIT License

Check if given function is bound or not.

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

You might also be interested in bind-context.

Install

npm i is-bound-function --save

Usage

For more use-cases see the tests

const isBoundFunction = require('is-bound-function')

isBoundFunction

Check fn is bound function, false otherwise.

Params

  • fn {Function}
  • returns {Boolean}

Example

var isBoundFunction = require('is-bound-function')

function fixture () { return this.foo || 'abc' }

console.log(isBoundFunction(fixture)) // => false
console.log(isBoundFunction(fixture.bind({foo: 'bar'}))) // => true

Notice that if you consider using bind-context library it will be different case.
It tries to solve exactly this problem and actually do it well for now.

var bind = require('bind-context')
var isBound = require('is-bound-function')

function foobar () { return this.baz }

console.log(isBound(foobar))                      // => false
console.log(isBound(foobar.bind({ baz: 123 })))   // => true
console.log(isBound(bind({ baz: 123 }, foobar)))  // => false

var nativeBound = foobar.bind({ a: 'b' })
var customBound = bind({ a: 'b' }, foobar)

console.log(nativeBound.toString()) // => function () { [native code] }
console.log(customBound.toString()) // => function foobar () { return this.baz }

So yea, that's the awesome point of this lib! :yum:

Related

You might also be interested in these packages:

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.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github