office-ui-fabric-react
Version: 
Reusable React components for building experiences for Office 365.
38 lines (36 loc) • 955 B
JavaScript
;
/**
 * Autobind is a utility for binding methods in a class. This simplifies tagging methods as being "bound" to the this pointer
 * so that they can be used in scenarios that simply require a function callback.
 *
 * @example
 * import { autobind } from '../utilities/autobind';
 *
 * public class Foo {
 *   @autobind
 *   method() {
 *   }
 * }
 */
function autobind(target, key, descriptor) {
    var fn = descriptor.value;
    return {
        configurable: true,
        get: function () {
            if (this === fn.prototype) {
                return fn;
            }
            return fn.bind(this);
        },
        set: function (newValue) {
            Object.defineProperty(this, key, {
                configurable: true,
                writable: true,
                enumerable: true,
                value: newValue
            });
        }
    };
}
exports.autobind = autobind;
//# sourceMappingURL=autobind.js.map