JavaScript 语言支持
能力与 src/core.cpp、src/internal.cpp 源码对齐。生产脚本建议显式写分号。
字面量与类型
undefined; null; true; false;
123; 3.14; 0x10;
"abc"; 'xyz';
({a:1, b:2});
[1, 2, 3];
变量
let与const(不支持var)- 复合赋值:
+= -= *= /= %=及位运算变体 - 后缀自增减
i++/i-- - 对
const重新赋值报错:assignment to constant
运算符
算术、位运算、比较、宽松/严格相等、逻辑、三元运算符与 typeof。
控制流
if/else、for、while、do...while、switch、break、continue、try/catch/finally、throw、return。
函数与闭包
- 函数声明、函数表达式、IIFE
- 箭头函数:
x => x*2、(a,b) => a+b、块体 - 词法闭包 — 嵌套函数捕获定义时的作用域
for (let i = 0; ...)每次迭代独立绑定(循环闭包行为正确)
// 闭包示例
function a() {
let x = 1;
function b() {
let y = 2;
return function c() { return x + y; };
}
return b();
}
a()(); // 3
// 循环闭包
let funcs = [];
for (let i = 0; i < 3; i++) {
funcs[i] = function() { return i; };
}
funcs[0](); // 0
核心内置(不含扩展)
String 方法
length、charCodeAt、charAt、indexOf、substring
Array 方法
push、pop、shift、slice、reverse、sort、splice、forEach、map、every、some、find、findIndex、reduce、indexOf、join
不支持(当前版本)
| 特性 | 说明 |
|---|---|
var、class、new | 解析/运行时报错 |
this、delete、with | 未实现 |
yield、void、in、instanceof | 未实现 |
| ES 模块、Promise、原型链 | 不支持 |
常见错误
parse error、; expected、type mismatch、'xxx' not found、oom、C stack — 多数带 at line N col M 位置信息。