CohesionBehavior类的active
方法用于激活行为的运行。该方法将启动行为并开始执行其规则。
CohesionBehavior.active()
该方法没有参数。
该方法不返回任何值。
CohesionBehavior.addRule()
方法添加规则。const behavior = new CohesionBehavior();
behavior.addRule("temperature", (event) => {
if (event.value > 25) {
console.log("温度过高,执行自动开启空调程序。");
// 执行自动开启空调程序
}
});
behavior.active();
在上述示例中,创建了一个名为 behavior
的 CohesionBehavior 实例。在添加了一个规则之后,调用了 active
方法,开始行为的运行。如果检测到温度超过25摄氏度,将会执行自动开启空调程序。
@end