Skip to content

tunnckoCore/is-bound-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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')

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! 😋

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.

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

About

Check if given function is bound or not.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published