UNPKG

976 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.bind = bind;
7
8function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
10var assign = Object.assign;
11/**
12 * Bind an infinite set of methods to a class instance.
13 *
14 * @param {Object} instance
15 * Instance of a class
16 * @param {...string} methods
17 * Method names of a class
18 */
19
20function bind(instance) {
21 var reduceBoundMethods = function reduceBoundMethods(accumulator, name) {
22 return assign(accumulator, _defineProperty({}, name, instance[name].bind(instance)));
23 };
24
25 for (var _len = arguments.length, methods = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
26 methods[_key - 1] = arguments[_key];
27 }
28
29 var boundMethods = methods.reduce(reduceBoundMethods, {});
30 assign(instance, boundMethods);
31}
\No newline at end of file