UNPKG

react-bootstrap

Version:

Bootstrap 3 components build with React

26 lines (22 loc) 601 B
/** * Safe chained function * * Will only create a new function if needed, * otherwise will pass back existing functions or null. * * @param {function} one * @param {function} two * @returns {function|null} */ function createChainedFunction(one, two) { let hasOne = typeof one === 'function'; let hasTwo = typeof two === 'function'; if (!hasOne && !hasTwo) { return null; } if (!hasOne) { return two; } if (!hasTwo) { return one; } return function chainedFunction() { one.apply(this, arguments); two.apply(this, arguments); }; } export default createChainedFunction;