Can a switch case test if a value meets a complex condition instead of just equality comparison?
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' )) {}