ant-design-vue/components/_util/createChainedFunction.js

23 lines
496 B
JavaScript
Raw Normal View History

2018-02-05 11:12:41 +00:00
/**
* Safe chained function
*
* Will only create a new function if needed,
* otherwise will pass back existing functions or null.
*
* @returns {function|null}
*/
2019-01-12 03:33:27 +00:00
export default function createChainedFunction() {
const args = [].slice.call(arguments, 0);
2018-02-05 11:12:41 +00:00
if (args.length === 1) {
2019-01-12 03:33:27 +00:00
return args[0];
2018-02-05 11:12:41 +00:00
}
2019-01-12 03:33:27 +00:00
return function chainedFunction() {
2018-02-05 11:12:41 +00:00
for (let i = 0; i < args.length; i++) {
if (args[i] && args[i].apply) {
2019-01-12 03:33:27 +00:00
args[i].apply(this, arguments);
2018-02-05 11:12:41 +00:00
}
}
2019-01-12 03:33:27 +00:00
};
2018-02-05 11:12:41 +00:00
}