I know that the case switch statement is an integral part of javascript, and you cannot change it. I'm still learning javascript and jQuery, so I can get around it, but I donβt know enough to write something that might be at the level of jQuery itself. So, take this as an idea or a question about whether this idea is possible.
This is my idea, a case switch statement that can use objects ... which can be used something like this:
switch( $(this) ){
case .hasClass('foo'):
// do something
break;
case .filter('.bar').attr('id') == 'foo':
// do something else
break;
}
Edit: even something like this would be nice (maybe a more sensible idea) ...
switch ($(this).hasClass()) {
case 'foo':
alert('found a foo!');
break;
case 'bar':
alert('found a bar!');
break;
}
source
share