-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
114 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#### All you need to know about `arguments` | ||
# `arguments` is special | ||
|
||
There are numerous ways to use arguments in a way that causes the function to be unoptimizable. One must be extremely careful when using arguments. | ||
There are numerous ways to use `arguments` in a way that causes the function to be unoptimizable. One must be extremely careful when using `arguments`. | ||
|
||
Only use: | ||
|
||
* `arguments.length`. | ||
* `arguments[i]` where `i` is always a valid integer index into the `arguments`, and can not be out of bound. | ||
* Never use `arguments` directly without `.length` or `[i]`. | ||
* STRICTLY `fn.apply(y, arguments)` is ok, nothing else is, e.g. `.slice`. `Function#apply` is special. | ||
* 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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
# Reallocation | ||
|
||
A good approach for performance is reuse instance in favour to avoid create a new instance and the costs that it represents. | ||
Instead of declare a new `Array` and reserving memory for that, you can reallocate an `Array` previously declared. | ||
|
||
If you want to remove the content of an array, use [`Array.prototype.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length): | ||
The thing that you need is remove the content of the array; You can do that using [`Array.prototype.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length): | ||
|
||
```js | ||
var array = [1, 2, 3, 4, 5] | ||
|
||
/* do something */ | ||
|
||
array = [] // bad | ||
array.length = 0 // good! | ||
``` | ||
|
||
Another good approach to use `.length` is when you know the size of your `Array`. In this case you can reserve the necessary memory space: | ||
|
||
```js | ||
var array = [] | ||
arr.length = 5 | ||
|
||
arr[0] = 1 | ||
arr[1] = 2 | ||
arr[2] = 3 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
# Table of contents | ||
|
||
* [JS MythBusters](/README.md) | ||
* [Send your tip!]() | ||
* [Bibliography](/bibliography.md) | ||
* [Resources](/resources.md) | ||
|
||
* [Array] | ||
* [Reallocation](/array/reallocation.md) | ||
* [Array.pop() better than Array.shift()] | ||
* [All you need to know about arguments] | ||
* [.pop over .shift](/array/pop-or-shift.md) | ||
* [arguments is special](/array/arguments.md) | ||
* [Date] | ||
* [Create timestamps with Date.now()] | ||
* [Creating timestamps](/date/timestamp.md) | ||
* [Error] | ||
* [Avoid try/catch] | ||
* [Avoid try/catch](/error/try-catch.md) | ||
* [Function] | ||
* [Make Your Constructors new-Agnostic] | ||
* [Avoid .bind, is slower] | ||
* [new agnostic](/function/new.md) | ||
* [.bind is slower](/function/bind.md) | ||
* [RegexEp] | ||
* [Use RegExp in cases with sense] | ||
* [Focus RegExp on failing faster] | ||
* [Use the correct RegExp method] | ||
* [Common sense](/regexp/common-sense.md) | ||
* [Focus on failing faster](/regexp/fail-faster.md) | ||
* [Correct method](/regexp/methods.md) | ||
* [String] | ||
* [Instead of String.concat, use '+='] | ||
* [+= for concat](/string/concat.md) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"github": "rstacruz/onmount", | ||
"github": "Kikobeats/js-mythbusters", | ||
"css": [ | ||
"assets/css/build.css" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.