javascript - Break out of an if statement -
jshint telling me not use label on if statement (it seems labels loops far jshint concerned).
forminjection: if (options.addtoform !== false) { if (!(options.addtoform instanceof jquery)) { options.addtoform = $(element).closest("form"); if (options.addtoform.length === 0) { options.addtoform = false; break forminjection; } } $(element).each(function(index){ //do stuff }); } so i'm getting warning on first line above (naturally) on break line.
update: code works intended not right way achieve end result. how should refactored?
okay, i'm testing cleaned solution
if (options.addtoform instanceof jquery || options.addtoform === true) { if (options.addtoform === true) { options.addtoform = $(element).closest("form"); } if (options.addtoform.length === 0) { // no form found options.addtoform = false; } } if (options.addtoform !== false) { $(element).each(function(index) { // stuff }); }
Comments
Post a Comment