vanilladocs
vanillapunch.com
API / base/identifier

base/identifier

식별자 생성기.

Identifier generator.

Identifierextends Object

짝Counterpart: vanilla-engine Identifier

식별자 생성기.

Identifier generator.

예제Example번호 차례로 나눠 주기Hand out numbers in order
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);
생성자constructorconstructor(initialSerialNumber = 0, initialIncreaseNumber = 1)#0.0.8 부터since 0.0.8소스source

생성.

Constructor.

initialSerialNumbernumber
처음 값. (기본 0, 첫 auto() 는 이 값에 증가량을 더해 돌려준다)Initial value. (default 0, the first auto() returns this value plus the increment)
initialIncreaseNumbernumber
auto() 한 번에 더할 기본 증가량. (기본 1)Default increment added per auto(). (default 1)

짝Counterpart: vanilla-engine Identifier.new

메서드methodreset()#0.0.8 부터since 0.0.8소스source

초기 상태로 되돌림. (처음 값부터 다시 센다)

Resets to the initial state. (Counts again from the first value)

짝Counterpart: vanilla-engine Identifier.reset

메서드methodauto(increaseNumber = 0)#0.0.8 부터since 0.0.8소스source

호출마다 (1 or custom)씩 증가되는 식별자 반환.

Returns an identifier incremented by (1 or custom) on each call.

increaseNumbernumber
이번에만 더할 증가량. (0 이거나 생략하면 기본 증가량)Increment for this call only. (the default increment if 0 or omitted)

반환Returnsnumber 더한 뒤의 식별자.The identifier after adding.

짝Counterpart: vanilla-engine Identifier.auto

Enumextends Object

열거 식별자 생성기.

Enum identifier generator.

예제Example상태 열거 만들기Make a state enumeration
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));
정적staticstatic begin()#0.0.8 부터since 0.0.8소스source

시작값으로 출발.

Starts from the start value.

반환Returnsnumber 처음부터 다시 센 첫 값. (늘 1)The first value after counting again from the start. (always 1)

정적staticstatic auto()#0.0.8 부터since 0.0.8소스source

값을 증가시켜서 반환.

Increments the value and returns it.

반환Returnsnumber 하나 늘린 값.The value increased by one.

정적staticstatic readonly(dictionary)#0.0.9 부터since 0.0.9소스source

고정 열거체 생성.

Creates a frozen enum.

dictionaryobject
얼릴 열거 객체. (그 자리에서 Object.freeze 한다)Enumeration object to freeze. (Object.freeze in place)

반환Returnsobject 얼린 dictionary 그 객체. (Object.freeze 처럼 받은 객체를 그대로 돌려준다)The frozen dictionary itself. (returns the given object as is, like Object.freeze)