base/reflection
리플렉션 함수 모음. (값이 있는지, 꼴 검사, 클래스 상속 검사, 복제, 고유식별자)
Reflection functions. (presence checks, type checks, class inheritance checks, cloning, unique identifiers)
import { Reflection, Vector2 } from "./build/vanilla.js";
const position = Vector2.create(3, 4);
const copied = Reflection.clone(position);
console.log(Reflection.isClassInstance(copied, Vector2), copied.x, copied.y);
console.log(Reflection.isPrimitiveType(123), Reflection.isArrayType([1, 2]));
console.log(Reflection.isValidate(null), Reflection.createGUID());함수Functions
유효한 객체인지 여부 반환.
Returns whether the object is valid.
- targetT
- 검사할 값.Value to check.
반환Returnsboolean undefined 나 null 이 아니면 참.True if it is neither undefined nor null.
인스턴스 얕은 복제.
Shallow clone of an instance.
- targetT
- 복제할 객체. (객체가 아니거나 없으면 오류를 던진다)Object to clone. (throws an error if it is not an object or is missing)
반환ReturnsT 같은 생성자를 인자 없이 불러 만든 새 객체. (자기 속성과 getter, setter 짝 속성을 얕게 옮긴다)A new object made by calling the same constructor with no arguments. (own properties and getter/setter pair properties are copied shallowly)
인스턴스 깊은 복제.
Deep clone of an instance.
- targetT
- 복제할 객체. (객체가 아니거나 없으면 오류를 던진다)Object to clone. (throws an error if it is not an object or is missing)
반환ReturnsT 같은 생성자를 인자 없이 불러 만든 새 객체. (배열과 일반 객체는 깊게, 클래스 인스턴스 값은 참조 그대로 옮긴다)A new object made by calling the same constructor with no arguments. (arrays and plain objects are copied deeply, class instance values keep their references)
import { Reflection } from "./build/vanilla.js";
class Inventory {
constructor() {
this.itemList = ["sword"];
}
}
const original = new Inventory();
const shallowCopy = Reflection.clone(original);
const deepCopy = Reflection.structuredClone(original);
original.itemList.push("shield");
console.log(shallowCopy.itemList.length, deepCopy.itemList.length);고유식별자 생성.
- "0192a3f2-b1c4-4d8e-8f1a-0e5d4c3b2a19"
Generates a unique identifier.
- "0192a3f2-b1c4-4d8e-8f1a-0e5d4c3b2a19"
반환Returnsstring "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" 꼴의 36 글자 문자열. (앞 12 자리는 밀리초 시각)A 36 character string shaped "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx". (the first 12 digits are the time in milliseconds)
짝Counterpart: vanilla-engine create_guid
원시 타입 여부 반환.
- undefined / null / boolean / number / bigint / string / symbol 이면 true.
- 예) isPrimitiveType(123) → true, isPrimitiveType({}) → false
Returns whether it is a primitive type.
- true for undefined / null / boolean / number / bigint / string / symbol.
- e.g. isPrimitiveType(123) → true, isPrimitiveType({}) → false
- targetT
- 검사할 값.Value to check.
반환Returnsboolean 원시 타입이면 참.True if it is a primitive type.
참조 타입 여부 반환.
- object / array / function 등 (null 제외).
- 예) isReferenceType({}) → true, isReferenceType(null) → false
Returns whether it is a reference type.
- object / array / function, etc. (excluding null).
- e.g. isReferenceType({}) → true, isReferenceType(null) → false
- targetT
- 검사할 값.Value to check.
반환Returnsboolean 객체나 함수면 참. (null 은 거짓)True if it is an object or a function. (false for null)
배열 타입 여부 반환.
- 예) isArrayType([1, 2, 3]) → true, isArrayType("abc") → false
Returns whether it is an array type.
- e.g. isArrayType([1, 2, 3]) → true, isArrayType("abc") → false
- targetT
- 검사할 값.Value to check.
반환Returnsboolean 배열이면 참.True if it is an array.
함수 타입 여부 반환.
- 일반 함수 / 화살표 함수 / 클래스 모두 typeof 가 "function" 이므로 true.
- 예) isFunctionType(() => {}) → true, isFunctionType(123) → false
Returns whether it is a function type.
- Regular functions / arrow functions / classes all have typeof "function", so true.
- e.g. isFunctionType(() => {}) → true, isFunctionType(123) → false
- targetT
- 검사할 값.Value to check.
반환Returnsboolean 함수면 참. (클래스 포함)True if it is a function. (classes included)
클래스/생성자 함수 여부 반환.
- typeof 가 "function" 이고 prototype 을 가진 경우 true (화살표 함수 제외).
- 예) isType(WorldNode) → true, isType(() => {}) → false
Returns whether it is a class/constructor function.
- true if typeof is "function" and it has a prototype (excluding arrow functions).
- e.g. isType(WorldNode) → true, isType(() => {}) → false
- targetT
- 검사할 값.Value to check.
반환Returnsboolean prototype 을 가진 함수면 참.True if it is a function that has a prototype.
특정 클래스의 인스턴스 여부 반환.
- target 이 type 또는 그 하위 타입의 인스턴스이면 true.
- 예) isClassInstance(new Vector2(), Vector2) → true
Returns whether it is an instance of a specific class.
- true if target is an instance of type or one of its subtypes.
- e.g. isClassInstance(new Vector2(), Vector2) → true
- targetT
- 검사할 값.Value to check.
- typeFunction
- 클래스.Class.
반환Returnsboolean target 이 type 이나 그 하위 클래스의 인스턴스면 참.True if target is an instance of type or one of its subclasses.
target 클래스가 type 클래스의 부모(상위) 클래스인지 여부 반환.
- type 이 target 을 (직간접적으로) 상속하면 true.
- target === type 인 경우는 false.
- 예) isParent(TransformNode, WorldNode) → true
Returns whether the target class is a parent (ancestor) class of the type class.
- true if type (directly or indirectly) inherits from target.
- false when target === type.
- e.g. isParent(TransformNode, WorldNode) → true
- parentTypeFunction
- 부모인지 볼 클래스.Class to check as the parent.
- targetTypeFunction
- 자식 쪽 클래스.Class on the child side.
반환Returnsboolean targetType 이 parentType 을 직간접으로 상속하면 참. (같은 클래스면 거짓)True if targetType inherits parentType directly or indirectly. (false for the same class)
target 클래스가 type 클래스의 자식(하위) 클래스인지 여부 반환.
- target 이 type 을 (직간접적으로) 상속하면 true.
- target === type 인 경우는 false.
- 예) isChildren(WorldNode, TransformNode) → true
Returns whether the target class is a child (descendant) class of the type class.
- true if target (directly or indirectly) inherits from type.
- false when target === type.
- e.g. isChildren(WorldNode, TransformNode) → true
- targetTypeFunction
- 자식인지 볼 클래스.Class to check as the child.
- parentTypeFunction
- 부모 쪽 클래스.Class on the parent side.
반환Returnsboolean targetType 이 parentType 을 직간접으로 상속하면 참. (같은 클래스면 거짓)True if targetType inherits parentType directly or indirectly. (false for the same class)