0.1.0 • Published 9 years ago
@optimal/arguments v0.1.0
@optimal/arguments
Optimal conversion of arguments to an array (allows optimization, no leaked memory).
Optimization is prevented when doing [].slice.call(arguments)
or Array.prototype.slice.call(arguments)
.
It's a "leak" when the arguments
is passed to another function or returned from a function.
So, we must create an array from the arguments. This would be an annoying bit of repetitive code.
This library takes care of this for you.
See article
Install
npm install @optimal/arguments --save
Usage
var arrayOf = require('@optimal/arguments')
function optimizable() {
// these are bad:
// [].slice.call(arguments)
// [].slice.call(arguments, 1)
// arguments[3] // when 3 is an invalid index
// return arguments
// this creates a new array without looping
var args = arrayOf(arguments)
// Or, select arguments with start/end like slice():
var args = arrayOf(arguments, 1, 3)
// now you can do this:
callAnotherFunction(args)
// or this:
return args
}
MIT License
0.1.0
9 years ago