on
以简单的方式添加一条命令。
artyom.on 方法是 artyom.addCommands的等价代替,其仅仅是作为语法糖存在。对于只有几个命令将会被使用的 artyom 项目中,该方法将会更加便利。
普通的command
let artyom = new Artyom();
artyom.on(['Good morning','Good afternoon']).then(function(i){
switch (i) {
case 0:
artyom.say("Good morning, how are you?");
break;
case 1:
artyom.say("Good afternoon, how are you?");
break;
}
});
smart command
如果你希望创建一个smart command,需要将on 函数接受的第二个参数设定为true:
artyom.on(['Repeat after me *'] , true).then(function(i,wildcard){
artyom.say("You've said : " + wildcard);
});
Last updated
Was this helpful?