我想知道在执行代码块时是否有可能在Javascript switch语句中使用类似于“ this”的东西。
例如:
switch(x) {
case 'The pyramids of Giza':
console.log(this);
break;
case 'The Leaning Tower of Pisa':
console.log(this);
break;
default:
console.log('Not found');
}
Run Code Online (Sandbox Code Playgroud)
是相同的:
switch(x) {
case 'The pyramids of Giza':
console.log('The pyramids of Giza');
break;
case 'The Leaning Tower of Pisa':
console.log('The Leaning Tower of Pisa');
break;
default:
console.log('Not found');
}
Run Code Online (Sandbox Code Playgroud)
纯粹出于效率目的,谢谢!