简单定时器实现
; 示例 #4: 使用 method 作为定时器子程序. counter := new SecondCounter counter.Start() Sleep 5000 counter.Stop() Sleep 2000 ; 一个记录秒数的示例类... class SecondCounter { __New() { this.interval := 1000 this.count := 0 ; Tick() 有一个隐式参数 "this" 引用一个对象 ; 所以 ; 我们需要创建一个封装 "this" 和 Tick 方法的函数来调用: this.timer := ObjBindMethod(this, "Tick") } Start() { ; 已知限制: SetTimer 需要一个纯变量引用. timer := this.timer SetTimer % timer, % this.interval ToolTip % "Counter started" } Stop() { ; 在此之前传递一个相同的对象来关闭定时器: timer := this.timer SetTimer % timer, Off ToolTip % "Counter stopped at " this.count } ; 本例中,定时器调用了以下方法: Tick() { ToolTip % ++this.count } }