I am new to scripting side and again need your help to write better code. I am using init function which is a collection of all functions, but now there seems to be few functions that I want to be executed if certain condition is true.
SAMPLE SCRIPT
$(document).ready(function() {
var app = {
init: function(){
// Variable to check condition
var abc = 0;
// Default functions
this.Function1();
this.Function2();
this.Function3(); // abc variable will change to 1 if condition is true
// Conditional functions
if ( abc === 1 ) {
this.ConditionFunction1();
this.ConditionFunction2();
},
Function1: function(){ // some Code },
Function2: function(){ // some Code },
Function3: function(){
if(true) { abc == 1; }
},
ConditionFunction1: function(){ // some Code },
ConditionFunction2: function(){ // some Code }
}
app.init();
});
abcis hard-coded to0, so your condition will never hit. If you want to perform some logic when theabcvalue changes, I'd suggest you use an event based patter instead.