4.1.2 • Published 5 years ago

bind-x v4.1.2

Weekly downloads
40
License
MIT
Repository
github
Last release
5 years ago

bind-x

Creates a new function with a bound sequence of arguments.

module.exportsfunction

The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.

Kind: Exported member
Returns: function - The bound function.
Throws:

  • TypeError If target is not a function.
ParamTypeDescription
targetfunctionThe target function.
thisArg*The value to be passed as the this parameter to the target function when the bound function is called. The value is ignored if the bound function is constructed using the new operator.
args...*Arguments to prepend to arguments provided to the bound function when invoking the target function.

Example

import bind from 'bind-x';

this.x = 9; // this refers to global "window" object here in the browser
const module = {
  x: 81,
  getX: function() {
    return this.x;
  },
};

console.log(module.getX()); // 81

const retrieveX = module.getX;
console.log(retrieveX());
// returns 9 - The function gets invoked at the global scope

// Create a new function with 'this' bound to module
// New programmers might confuse the
// global var x with module's property x
const boundGetX = bind(retrieveX, module);
console.log(boundGetX()); // 81
4.1.2

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.15

5 years ago

4.0.14

5 years ago

4.0.13

5 years ago

4.0.12

5 years ago

4.0.11

5 years ago

4.0.10

5 years ago

4.0.9

5 years ago

4.0.8

5 years ago

4.0.7

5 years ago

4.0.6

5 years ago

4.0.5

5 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.0.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago