# special function

## debounce data

![](https://4116032991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgnugJ0SdX2tMAwP37V%2F-Lhh6SPpD8GePSbPj5Q5%2F-Lhh95c5waXBTE8LIU4x%2Fimage.png?alt=media\&token=beec1370-e08f-46f0-b726-67d99fb3a276)

Operation DOM:

let temp = document.getElementsByTagName("a"); for (let i of temp) { console.log(i.innerHTML); }

![](https://4116032991-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgnugJ0SdX2tMAwP37V%2F-Li7HgE4sQxtlrVUTAw-%2F-Li7HggSqwh9TPexZyW6%2Fimage.png?alt=media\&token=50eb3aa1-0905-486d-b00a-dbc256fe2356)

Random array

**for (let i = temp.length - 1; i >= 0; i--) {**

&#x20;   **let j = Math.floor(Math.random() \* (i + 1));**

&#x20;   **\[temp\[i], temp\[j]] = \[temp\[j], temp\[i]];**

**}**\\

## 7 ways to flip two varibles

a = "hello", b = "bye";

1. var c = a; a = b; b = c;
2. &#x20;a = a + b; b = a - b; a = a - b;        -------- a = a - b; b = a + b; a = b - a;
3. a ^= b; b ^= a; a ^= b;          a = (b^=a^=b)^a;
4. a = {a:b,b:a}; b = a.b; a = a.a;
5. a = \[a,b]; b = a\[0]; a = a\[1];
6. a = \[b,b=a]\[0];                   -------    &#x20;

   ```
   b = [a, a = b][0];

   a = b + (b = a, "");
   ```
7. \[a,b] = \[b,a];

## *generator*&#x20;

*Generator function*

function\* generator(i) { yield i; yield i + 10; }

#### GeneratorFunction

```
Object.getPrototypeOf(function*(){}).constructor
```

#### function\* expression

const foo = function\*() { yield 'a'; yield 'b'; yield 'c'; };

[`Generator.prototype.next()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)

Returns a value yielded by the [`yield`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield) expression.

[`Generator.prototype.return()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)

Returns the given value and finishes the generator.

[`Generator.prototype.throw()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)

Throws an error to a generator (also finishes the generator, unless caught from within that generator).

```
function* infinite() {
    let index = 0;

    while (true) {
        yield index++;
    }
}

const generator = infinite(); // "Generator { }"

console.log(generator.next().value); // 0
console.log(generator.next().value); // 1
```
