What is the best way to inject a value into the middle of arguments?
- Would prefer it to be a one liner
- Need it to be really fast!
JSPerf here: http://jsperf.com/inject-into-arguments
Of the two below "slice-and-concat.js" is 12% faster in Chrome.
What is the best way to inject a value into the middle of arguments?
JSPerf here: http://jsperf.com/inject-into-arguments
Of the two below "slice-and-concat.js" is 12% faster in Chrome.
| function fn() { | |
| return [arguments[0],'INJECTED VALUE'].concat(Array.prototype.slice.call(arguments, 1)); | |
| } | |
| fn(1, 2, 3, 4); |
| function fn() { | |
| var args = Array.prototype.slice.call(arguments); | |
| args.splice(1,0,'INJECTED VALUE'); | |
| return args; | |
| } | |
| fn(1, 2, 3, 4); |