UNPKG

1.04 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var constants;
4(function (constants) {
5 constants.typeOfFunction = 'function';
6 constants.boolTrue = true;
7})(constants || (constants = {}));
8function bind(target, propertyKey, descriptor) {
9 if (!descriptor || (typeof descriptor.value !== constants.typeOfFunction)) {
10 throw new TypeError("Only methods can be decorated with @bind. <" + propertyKey + "> is not a method!");
11 }
12 return {
13 configurable: constants.boolTrue,
14 get: function () {
15 var bound = descriptor.value.bind(this);
16 // Credits to https://github.com/andreypopp/autobind-decorator for memoizing the result of bind against a symbol on the instance.
17 Object.defineProperty(this, propertyKey, {
18 value: bound,
19 configurable: constants.boolTrue,
20 writable: constants.boolTrue
21 });
22 return bound;
23 }
24 };
25}
26exports.bind = bind;
27exports.default = bind;