gpt4 book ai didi

javascript - 是否可以将 instanceof 运算符结果作为值获取?

转载 作者:行者123 更新时间:2023-11-30 14:07:20 25 4
gpt4 key购买 nike

<分区>

假设我有一个变量可以表示许多不同的模型(对象)。我想以不同的方式回应每一个,最好是通过 switch 语句。是否可以将 instanceof 结果作为值获取?

例如,像这样:

function determineModel(model) {
switch (model instanceof) { // this does not work
case 'Foo':
// do something
break;
case 'Bar':
// do something else
break;
default:
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com