UNPKG

494 BJavaScriptView Raw
1/**
2 * Safe chained function
3 *
4 * Will only create a new function if needed,
5 * otherwise will pass back existing functions or null.
6 *
7 * @returns {function|null}
8 */
9export default function createChainedFunction() {
10 var args = [].slice.call(arguments, 0);
11
12 if (args.length === 1) {
13 return args[0];
14 }
15
16 return function chainedFunction() {
17 for (var i = 0; i < args.length; i++) {
18 if (args[i] && args[i].apply) {
19 args[i].apply(this, arguments);
20 }
21 }
22 };
23}
\No newline at end of file