javascript built-in object bindings (Object, Array, JSON, RegExp, Symbol, Proxy, ...)
| Package | Binds | Note |
|---|---|---|
| array | JsArray | JS Array as a non-generic Array[Any]; converts to MoonBit Array[T] |
| arraybuffer | ArrayBuffer, SharedArrayBuffer, DataView, TypedArray | All typed arrays (Uint8Array, Float64Array, BigInt64Array, …); zero-cost Bytes ⇔ Uint8Array |
| atomics | Atomics | add/load/store/wait/notify on shared memory |
| bigint | JsBigInt | Arbitrary-precision integers |
| collection | JsMap, JsSet | JS Map and Set |
| date | Date | Timestamps, components, formatting |
| disposable | DisposableStack, AsyncDisposableStack | Explicit resource management |
| error | JsError, TypeError, RangeError, ReferenceError, SyntaxError, URIError, EvalError, AggregateError | The error hierarchy |
| function | Function | call/apply/bind |
| global | Timer and the global functions | setTimeout, setInterval, queueMicrotask, globalThis, undefined, parseInt, atob/btoa, encodeURIComponent, structuredClone, dynamic_import, … |
| iterator | JsIterator, AsyncIterator | The iteration protocols |
| json | JSON | JSON.parse / JSON.stringify |
| math | Math | The Math namespace |
| object | Object, PropertyDescriptor | keys/values/entries/assign/freeze/defineProperty, … |
| proxy | Proxy | Proxy traps |
| reflect | Reflect | The Reflect namespace |
| regexp | RegExp, RegExpMatchArray, RegExpResult | Native JS regex |
| string | JsString | JS String methods not in MoonBit's String |
| symbol | Symbol | Well-known and user symbols |
| weak | WeakMap, WeakSet, WeakRef, FinalizationRegistry | Weak references |
# moon.mod
import {
"mizchi/js_core@0.13.0",
"mizchi/js_builtin@0.13.0",
}# moon.pkg
import {
"mizchi/js_core" @core,
"mizchi/js_builtin/json",
"mizchi/js_builtin/object",
}///|
pub fn describe() -> String {
let o = @core.new_object()
o["k"] = @core.any(1)
let any : @core.Any = o |> @core.identity
let _ = @object.Object::entries(any)
@json.JSON::stringify(any)
}Install
Download zipjavascript built-in object bindings (Object, Array, JSON, RegExp, Symbol, Proxy, ...)