扩展模块
可选模块编译进 libemjs-exts.a,运行时需显式 bind(CLI 会自动绑定)。
CMake 选项
| 选项 | 模块 |
|---|---|
BUILD_CONSOLE | console.* |
BUILD_GLOBAL | global.*(parseInt、parseFloat) |
BUILD_STRING | string.*(String.fromCharCode) |
BUILD_DATE | date.* |
BUILD_JSON | json.* |
BUILD_MATH | math.* |
运行时绑定
#include "extension/console.h"
#include "extension/global.h"
#include "extension/string.h"
#include "extension/date.h"
#include "extension/math.h"
#include "extension/json.h"
EConsole::bind(js);
EGlobal::bind(js);
EString::bind(js);
EDate::bind(js);
EMath::bind(js);
EJson::bind(js);
console
console.log(...args)console.time(label?)console.timeLog(label, ...args)console.timeEnd(label?)
global
parseInt(str[, radix])parseFloat(str)
String(全局对象)
String.fromCharCode(...codes)
Date
Date.now()Date.format([timestampMs][, format])
默认格式:%Y-%m-%d %H:%i:%s
Math
常量:E, LN10, LN2, LOG10E, LOG2E, PI, SQRT1_2, SQRT2
函数:abs acos acosh asin asinh atan atan2 atanh cbrt ceil clz32 cos cosh exp expm1 f16round floor fround hypot imul log log10 log1p log2 max min pow random round sign sin sinh sqrt sumPrecise tan tanh trunc
JSON
let o = JSON.parse('{"a":1,"b":[2,3]}');
JSON.stringify(o); // {"a":1,"b":[2,3]}
核心数组/字符串方法不依赖扩展模块 — 请参阅 JavaScript 特性。