如何使用switch语句实现类似以下的操作:
这相当于:
String.prototype.startsWith = function( str ){
return ( this.indexOf( str ) === 0 );
}
switch( myVar ) {
case myVar.startsWith( 'product' ):
// do something
break;
}
这相当于:
if ( myVar.startsWith( 'product' )) {}