title: Attempting to store value in object through nested functions
body: <p>I have been trying to follow best practices and contain my functions etc inside on one object. </p>
  
  <p>The goal is to attempt to have 2 methods that run when called, one to initialize and get the beginning value upon clicking... then with another method that runs when a user clicks the calculate button to perform a simple calculation based on the initial beginning value.</p>
  
  <p>Problem is that even though I have wrapped these methods inside of an anonymous function they should as I understand it reference the value of the parent objects property. In the init it sets it correctly and doing an output on value shows that its grabbed the right value of 77 for ex.</p>
  
  <p>Then I expect that now while still on the same page, <code>myObj.beginVal</code> should have a consistent value of 77 until changed..</p>
  
  <p>However, in when I run 'calculate' it does not have that value but the initial NULL value.
  I want its value to be whatever was set by the init function, which in this case was 77.</p>
  
  <p>No pages are being reloaded, and I have tried placing the creation of the <code>myObj</code> object inside and outside the doc ready with same results... I also made this global with hopes that it would retain its value when other methods try to access it.</p>
  
  <p>How do I accomplish this? What am I doing wrong?</p>
  
  <p>Any help would be much appreciated!</p>
  
  <pre><code>myObj = {};
  
  $(document).ready(function(){
  
      myObj = {               
          beginVal : null,  //initial value...
  
          init : function(evt) {
  
              $("#openCalculatorButton").bind("click", function() {
  
              myObj.beginVal = $($(this).parent().attr('id')); // 77
  
              $.fancybox.showActivity();
  
              $.ajax({
                  type    : "POST",
                  cache   : false,
                  url     : "/calc.php",
                  data    : myObj,
                  success : function(data) {
                      $.fancybox({
                          'content' : data
                      });
                  }
              });
  
              return false;
              });
          }, // function(evt)                             
  
  
          calculate : function(evt) {
  
              console.log(myObj.beginVal); // null
  
              $('#getAnswerButton').click(function(){ 
                  // Need the value of myObj.beginVal to be retained and at this point be 77! but it is NULL!         
  
                  myObj.answer = myObj.beginVal * 3.16;  // Create prop and set value of the original object
  
                  return false;
              });
  
          }
  
      }// calc
  });
  </code></pre>