結構匹配
假設以下結構:
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!";
}