我如何组织枚举,以便每个枚举条目都有参数,例如我在Haxe中可以做的,例如:
enum GraphicAct {
ClearScreen;
MoveTo(x:Float, y:Float);
LineTo(x:Float, y:Float);
FillColor(color:Int);
EndFill;
}
function main(){
var actions:Array<GraphicAct>;
actions.push(ClearScreen);
actions.push(FillColor(0xaaffff));
actions.push(MoveTo(100, 100));
actions.push(LineTo(200, 100));
actions.push(LineTo(100, 200));
actions.push(EndFill);
for(act in actions){
switch(act){
case ClearScreen: // do clear screen here...
case MoveTo(x, y): // move position
case LineTo(x, y): // move position
}
}
}
Run Code Online (Sandbox Code Playgroud)
据我所知,C++仅支持没有参数的枚举条目,如"ClearScreen"和"EndFill",但在这种情况下,我如何在C++中组织命令序列,就像我在图形命令中的例子一样?
当我加载页面时,我有一行:
<script>HUD = "hello";</script>,然后我打开页面,打开DevTools,转到控制台"并输入HUD- 我看到
VM331:1 Uncaught ReferenceError: HUD is not defined(…)
然后我重新加载页面,保持DevTools打开,然后再次进入HUD - 现在它存在并打印"你好"
<!DOCTYPE html>
<html>
<head lang="en">
<script>
var HUD = "hello";
console.log(HUD);
</script>
</head>
<body>
Open console and enter HUD - is it there?
</body>
</html>Run Code Online (Sandbox Code Playgroud)
运行代码段并以这种方式检查 - 有时HUD存在,有时则不存在.我想知道为什么...
我们有haxe.ds.ReadOnlyArray,但它阻止了每个人的推送/弹出。我需要的是能够在课堂内更改它,但不能在课堂外更改。是否可以?当我这样做时public var myArr(default, null):Array<Something>- 它不会让其他类替换数组本身,但它们可以推送/弹出,所以这也不是解决方案。谢谢!
我知道Haxe 中有一个关于类属性的常量问题。我的问题是:是否可以在函数内部定义常量?喜欢:
function foo(){
const bar=7;
bar = 8; // should prevent compilation
}
Run Code Online (Sandbox Code Playgroud)
也许像 var 之类的var foo:ReadOnlyInt东西?