# base/identifier (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/base/identifier/

식별자 생성기.

## Identifier extends Object

식별자 생성기.

예제: 번호 차례로 나눠 주기

```js
import { Identifier } from "./build/vanilla.js";

const identifier = new Identifier(1000, 1);
const firstId = identifier.auto();
const secondId = identifier.auto();
const jumpedId = identifier.auto(10);
console.log(firstId, secondId, jumpedId);

identifier.reset();
const restartedId = identifier.auto();
console.log(restartedId);
```

- `constructor(initialSerialNumber = 0, initialIncreaseNumber = 1)` (constructor, since 0.0.8): 생성.
  - `initialSerialNumber` number: 처음 값. (기본 0, 첫 auto() 는 이 값에 증가량을 더해 돌려준다)
  - `initialIncreaseNumber` number: auto() 한 번에 더할 기본 증가량. (기본 1)
- `reset()` (method, since 0.0.8): 초기 상태로 되돌림. (처음 값부터 다시 센다)
- `auto(increaseNumber = 0)` (method, since 0.0.8): 호출마다 (1 or custom)씩 증가되는 식별자 반환.
  - `increaseNumber` number: 이번에만 더할 증가량. (0 이거나 생략하면 기본 증가량)
  - returns number: 더한 뒤의 식별자.

## Enum extends Object

열거 식별자 생성기.

예제: 상태 열거 만들기

```js
import { Enum } from "./build/vanilla.js";

const GameState = {
	ready: Enum.begin(),
	playing: Enum.auto(),
	gameOver: Enum.auto()
};
Enum.readonly(GameState);
console.log(GameState.ready, GameState.gameOver, Object.isFrozen(GameState));
```

- `static begin()` (static, since 0.0.8): 시작값으로 출발.
  - returns number: 처음부터 다시 센 첫 값. (늘 1)
- `static auto()` (static, since 0.0.8): 값을 증가시켜서 반환.
  - returns number: 하나 늘린 값.
- `static readonly(dictionary)` (static, since 0.0.9): 고정 열거체 생성.
  - `dictionary` object: 얼릴 열거 객체. (그 자리에서 Object.freeze 한다)
  - returns object: 얼린 dictionary 그 객체. (Object.freeze 처럼 받은 객체를 그대로 돌려준다)
