How can I do something like this with a switch statement:
String.prototype.startsWith = function( str ){
return ( this.indexOf( str ) === 0 );
}
switch( myVar ) {
case myVar.startsWith( 'product' ):
// do something
break;
}
This is the equivalent of:
if ( myVar.startsWith( 'product' )) {}
You can do it, but it’s not a logical use of the
switchcommand: