UNPKG

@hemia/autobind

Version:

A lightweight utility for automatic method binding in classes

2 lines (1 loc) 1.01 kB
"use strict";function t(t,e,o){let r=o.value;if("function"!=typeof r)throw new TypeError("@BoundMethod decorator can only be applied to methods not: "+typeof r);let n=!1;return{configurable:!0,get(){if(n||this===t.prototype||Object.prototype.hasOwnProperty.call(this,e)||"function"!=typeof r)return r;const o=r.bind(this);return n=!0,Object.defineProperty(this,e,{configurable:!0,get:()=>o,set(t){r=t,delete this[e]}}),n=!1,o},set(t){r=t}}}function e(e){let o;return"undefined"!=typeof Reflect&&"function"==typeof Reflect.ownKeys?o=Reflect.ownKeys(e.prototype):(o=Object.getOwnPropertyNames(e.prototype),"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(e.prototype)))),o.forEach((o=>{if("constructor"===o)return;const r=Object.getOwnPropertyDescriptor(e.prototype,o);r&&"function"==typeof r.value&&Object.defineProperty(e.prototype,o,t(e,o,r))})),e}exports.Autobind=function(o,r,n){return 1===arguments.length?e(o):t(o,r,n)},exports.BoundClass=e,exports.BoundMethod=t;