Thursday, July 26, 2012

Simplify this If statement so it doesn't duplicate code – Javascript



I have an If statement that runs within a \’for\’ loop to create markers for a Google map. Basically if a tick box is not ticked it runs the code all displays all markers, but if a checkbox is ticked then it checks for a 2nd parameter and only runs the code for the items that match this condition.


The code I have below works fine, but it means I have to use the same code in both parts of the if statement. Apart from building it into a function if there a better way of structuring the If statement to achieve this?



if(!FriendlyChecked){

//Code here

} else if(FriendlyChecked && Friendly == \"Yes\"){

//Same code here

}






Rating: 5 out of 5 based on 3 ratings



The post Simplify this If statement so it doesn't duplicate code – Javascript appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/simplify-this-if-statement-so-it-doesnt-duplicate-code-javascript.html

No comments:

Post a Comment