avocado-old/packages/core/fast-apply.js
2019-05-02 20:55:14 -05:00

24 lines
535 B
JavaScript

export function fastApply(holder, fn, args) {
if (holder || args.length > 5) {
return fn.apply(holder, args);
}
if (0 === args.length) {
return fn();
}
if (1 === args.length) {
return fn(args[0]);
}
if (2 === args.length) {
return fn(args[0], args[1]);
}
if (3 === args.length) {
return fn(args[0], args[1], args[2]);
}
if (4 === args.length) {
return fn(args[0], args[1], args[2], args[3]);
}
if (5 === args.length) {
return fn(args[0], args[1], args[2], args[3], args[4]);
}
}