Jump to content

handling undefined variables


jimfog

Recommended Posts

I have this code-it is simplified so you can get an easier meaning out of it:

 select: function(start, end,allDay,event,fcEvent) {  monthclick=true;;//global      if(selectmonth===true)//global also here{...}.....   }changefrom: function(){   if(monthclick===true)
{
selectmonth=true;
$('#calendar').fullCalendar('select',start,end,allDay);//this line here calls the select function above
}

}

 

Τhe above code has 2 global variables,selectmonth and monthclick, and the code within changefrom() calls the select function directly above it.

 

The full code is here at line 60(select function) and line 260 (changefrom function) at this script here http://1drv.ms/1s6sdnG

Of course the code in the script is much more but I want you to focus on the problem with the global variables.

 

The existence of globals makes the code more complicated(conditionals...etc)...is this unavoidable or I can do something to avoid it?

 

Anything...

 

Link to comment
Share on other sites

yes I am defining an object...:

   this.eventView.model = new Event({start: Math.round(start.getTime()/ 1000), end: Math.round(end.getTime()/ 1000),allDay:false,color: '#0072C6'});            

I assume you mean adding properties to the above object.

 

Yes but how could I implement this....currently I set the values of these globals,check their value(using conditionals) and act accordingly.

 

How I could do that using object properties?

 

I am trying to think what re factoring to do?

Any help would be appreciates...an example maybe?

 

Do objects have global scope?

Edited by jimfog
Link to comment
Share on other sites

You'll need to read up on scope, you need to understand scope well to be able to do something like this effectively. You're already using things like this.select, it's the same thing. this is the scope, and then you put the property or method after it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...