Howdy.
I was just reading through the
Optimization Killers article on the Bluebird wiki, trying to work out whether the following would be optimized:
function get(/* ...k, j, i */) {
const a = arguments, l = a.length, n = l - 1
switch (l) {
case 0: return this
case 1: return this[a[n]]
default: return get.apply(this[a[a.length = n]], a) // a.length = n = a.length - 1
}
}
console.log(get.call({x:{y:{z:'!!!'}}}, 'z','y','x')) // => "!!!"
Shedding an argument in this way isn't really discussed (anywhere that I can find), but it seems like it should be okay (at least it doesn't
appear to be leaking).
Any insight would be highly appreciated. Thanks in advance!