结构匹配
假设以下结构:
var dog = {
name : "Woofer",
age : 7
};
枚举匹配可以按如下方式执行:
var message = switch(dog) {
case { name : "Woofer" }:
"I know you, Woofer!";
case _:
"I don't know you, sorry!";
}
假设以下结构:
var dog = {
name : "Woofer",
age : 7
};
枚举匹配可以按如下方式执行:
var message = switch(dog) {
case { name : "Woofer" }:
"I know you, Woofer!";
case _:
"I don't know you, sorry!";
}