is-bound-function
v1.0.1
Published
Check if given function is bound or not.
Downloads
4
Readme
is-bound-function
Check if given function is bound or not.
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:
- bind-context: Bind context to a function and preserves her name. Can be used… more | homepage
- function-arguments: Get arguments of a function, useful for and used in dependency injectors.… more | homepage
- is-async-function: Is function really asynchronous function? Trying to guess that based on check… more | homepage
- is-callback-function: Returns true if function is a callback. Checks its name is one… more | homepage
- parse-arguments: Parse function to object with same key names as arguments names and… more | homepage
- parse-function: Parse a function, arrow function or string to object with name, args,… more | homepage
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.