I've read that pop()/shift()
is significantly more performant than using slice()
. https://jsperf.com/pop-vs-slice/5
Here's my use case using slice():
proto.wrapErrorFirst = proto.wrapErrFirst = function (fn: Function) {
const self = this;
return function (err: IPseudoError) {
if (err) {
return self.__handle(err, false);
}
try {
// remove the error-first argument
return fn.apply(this, Array.from(arguments).slice(1));
}
catch (err) {
return self.__handle(err, false);
}
}
};
so this should be more performant:
proto.wrapErrorFirst = proto.wrapErrFirst = function (fn: Function) {
const self = this;
return function (err: IPseudoError) {
if (err) {
return self.__handle(err, false);
}
try {
const args = Array.from(arguments);
args.shift()
return fn.apply(this, args);
}
catch (err) {
return self.__handle(err, false);
}
}
};
but I am wondering if there is a way to do that with less code and perhaps a way to do that without having to call Array.from(arguments)?
maybe something kinda crazy like this:
delete arguments[0];
return fn.apply(this, arguments);