class EventLog { count: Object captureStep: Number methodStep: Number targetStep: Number bubbleStep: Number phase: String function capture(self: EventLog, event: Event): Unit { self.count.increment() self.captureStep = self.count.value self.phase = event.phase } function target(self: EventLog, event: Event): Unit { self.count.increment() self.targetStep = self.count.value self.phase = event.phase } function bubble(self: EventLog, event: Event): Unit { self.count.increment() self.bubbleStep = self.count.value self.phase = event.phase } } class EventButton: Button { model: EventLog function onEvent(self: EventButton, event: Event): Unit { self.model.count.increment() self.model.methodStep = self.model.count.value self.model.phase = event.phase } } model = EventLog(ui.state(0), 0, 0, 0, 0, "等待点击") button = EventButton("捕获 → 对象方法 → 监听器 → 冒泡", model) root = Column(24, 16, TextBlock("同一对象系统中的事件分派", 2), button, ui.textOf(model.count, "value"), ui.textOf(model, "phase")) capture = root.on("click", model.capture, "capture") target = button.on("click", model.target) bubble = root.on("click", model.bubble) page = Page() page.render(root)