Jump to content

"lifetime" of a variable


jimfog

Recommended Posts

Despite I am using the term "lifetime" here I am not sure this such a problem.

I am going to present code that is part of a bigger one...for simplicity reasons an hopefully you will get I meaning out of it.

  select: function(start, end) {  monthclick=true;           this.changefrommonth;                this.eventView.collection = this.collection;//ternary expressions follow                var starter=(this.changefrommonth===true)?console.log('jogh'):start.add(7,'h').format('YYYY-MM-DD HH:mm:ss');                var ender=(this.changetillmonth===true)?end.format('YYYY-MM-DD HH:mm:ss'):start.add(30,'m').format('YYYY-MM-DD HH:mm:ss');                var unx=this.unixconvert(starter,ender);                 this.eventView.model = new Event({start:unx[0]/1000 , end: unx[1]/1000,allDay:false,color: '#0072C6'});//Model inmstance created..                                this.eventView.dropfrom(starter);                this.eventView.droptill(ender);                this.eventView.render();                      }              },  changefrom:function(){        this.selestrt;        $("#timesfrom option:selected").each(function () {                                    var selstart=$('#timesfrom').val();                  var selectedtill=$('#timestill').val();                  if(selstart>=selectedtill)                  {           alert('Ουπς...η ώρα που ξεκινάει ένα ραντεβού δεν μπορεί να είναι πιο μπροστά από την ώρω που λήγει');                  this.dropfrom(this.selestrt,'true');                  return false;                                                              }                  var unixstartmili=selstart*1000,unixendmili=selectedtill*1000;                                   var start=new Date(unixstartmili),end=new Date(unixendmili);//                  var allDay = false;                                   if(monthclick===true)//focus in this conditional here                  {                                     this.changefrommonth=true;                     $('#calendar').fullCalendar('select',start,end,allDay);                     var test;                  }                  else                  {                   $('#calendar').fullCalendar('select',start,end,allDay);//το σφλαμα ειναι με το end εδώ                   selectmonth=false;                  }                  }.bind(this));                         },

Above you see 2 functions,in the second one,changefrom(),and in the conditional I have commented, a variable named this.changefrommonth has been set to true.

 

The purpose is that this assignment becomes available(in the ternary operators you see) in the select function which is depicted above.

When the conditional runs(and as I see in the chrome dev tools sources panel by placing various breakpoints) the assignment indeed takes place but when select is called with this line here:

 $('#calendar').fullCalendar('select',start,end,allDay);

the value of the variable is unset...not being true anymore.

You could say that I could use it as an argument in the above method...I want to try and avoid this for now as this method is provided by a plugin and I do not want to mesh with it's code for now.

 

I hope I was clear

 

Link to comment
Share on other sites

Which variable is not set? You never referred to it by its name. I think you might be referring to the "allDay" variable. In your code, I have not seen the variable allDay being set to anything other than false.

 

A variable declared globally never becomes unset. Variables that are local to a function are destroyed as soon as the function ends.

Link to comment
Share on other sites

The variable I am referring to is called this.changefrommonth.

 

Regarding the comments you make about global variables....lead me to make some more testing.

I will post again if it is required.

Link to comment
Share on other sites

It's a question about scope. The property is set on the this object, so if it is set in one but does not appear in the other then it sounds like they are being called with different scopes. this is set to something different in each. You could check what it is set to if you want to see.

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...