amis-rpc-design/node_modules/rc-util/lib/createChainedFunction.js

27 lines
598 B
JavaScript
Raw Normal View History

2023-10-07 19:42:30 +08:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = createChainedFunction;
/**
* Safe chained function
*
* Will only create a new function if needed,
* otherwise will pass back existing functions or null.
*
* @returns {function|null}
*/
function createChainedFunction() {
var args = [].slice.call(arguments, 0);
if (args.length === 1) {
return args[0];
}
return function chainedFunction() {
for (var i = 0; i < args.length; i++) {
if (args[i] && args[i].apply) {
args[i].apply(this, arguments);
}
}
};
}