jimfog Posted October 7, 2014 Share Posted October 7, 2014 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 More sharing options...
justsomeguy Posted October 7, 2014 Share Posted October 7, 2014 You're defining an object, so you should be able to define those as properties of the object instead of globals. Link to comment Share on other sites More sharing options...
jimfog Posted October 7, 2014 Author Share Posted October 7, 2014 (edited) 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 October 7, 2014 by jimfog Link to comment Share on other sites More sharing options...
justsomeguy Posted October 7, 2014 Share Posted October 7, 2014 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now