Skip to content

Commit

Permalink
Update arguments.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 22, 2017
1 parent 3a9a610 commit 46b52cf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/array/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,20 @@ Only use:
* STRICTLY `fn.apply(y, arguments)` is ok, nothing else is (e.g. `.slice`). That's because `Function#apply` is special.
* Be aware that adding properties to functions (e.g. `fn.$inject =...`) and bound functions (i.e. the result of `Function#bind`) generate hidden classes and, therefore, are not safe when using `.apply`.

If you need to manipulate `arguments`, use a copy. [sliced](https://github.com/aheckmann/sliced) is a good tiny library for this purpose.
If you need to process the input of a function as an `array`, a good perfomance approach is manipulate a copy of `arguments`. You can do it using `spread operator`:

```js
function spreadOp(...args) {
return other(args)
}
```

If you are in a scenario where is not possible to use `spread operator`, we recommend use the tiny [sliced](https://github.com/aheckmann/sliced) library for make an a copy of the `array`:

```js
const sliced = require('sliced');

function myFunctionWithArgs() {
const args = sliced(arguments)
}
```

0 comments on commit 46b52cf

Please sign in to comment.