Last active
September 27, 2020 07:25
-
-
Save jamesliu96/b5f3da494eb6c356ec09fdf9bcdfc436 to your computer and use it in GitHub Desktop.
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
const Primitives = { | |
uint8: Uint8Array, | |
uint16: Uint16Array, | |
uint32: Uint32Array, | |
int8: Int8Array, | |
int16: Int16Array, | |
int32: Int32Array, | |
float32: Float32Array, | |
float64: Float64Array, | |
}; | |
export default class Primitive { | |
static types = Primitives; | |
#primitive; | |
constructor(ctor, init = 0) { | |
this.#primitive = new ctor(1); | |
this.#primitive[0] = init; | |
} | |
get value() { | |
return this.#primitive[0]; | |
} | |
set value(v) { | |
this.#primitive[0] = v; | |
} | |
} |
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
const Primitives = { | |
uint8: Uint8Array, | |
uint16: Uint16Array, | |
uint32: Uint32Array, | |
int8: Int8Array, | |
int16: Int16Array, | |
int32: Int32Array, | |
float32: Float32Array, | |
float64: Float64Array, | |
}; | |
type PrimitivesType = typeof Primitives[keyof typeof Primitives]; | |
export default class Primitive { | |
public static types = Primitives; | |
#primitive: InstanceType<PrimitivesType>; | |
public constructor(ctor: PrimitivesType, init = 0) { | |
this.#primitive = new ctor(1); | |
this.#primitive[0] = init; | |
} | |
public get value() { | |
return this.#primitive[0]; | |
} | |
public set value(v: number) { | |
this.#primitive[0] = v; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment