title: Javascript object function calling another function within object, Rails
body: <p><strong>Original Question</strong></p>
  
  <p>Can't figure out why I can't call the second function from within that first function.  I am using jQuery-turbolinks.  (Also, if you happen to know of a better way to only run page-specific javascript in rails, let me know.   Currently this is my best implementation where I check if the body has a certain class, and if it does then I run the init function within this javascript object).</p>
  
  <p><strong><em>app/assets/javascripts/blogs.js</em></strong></p>
  
  <pre><code>$(document).ready(function(){
  
      var blogsjs = {   
          myBlog: this,  
          init: function(){
              alert("hello from blogs");
              $("input").on('click', function(){
                  $(this).hide('slow', function(){
                      myBlog.another();
                  });
              });
          },
          another: function(){
              alert("I was called!")
          }
      };
  
  
      if($('body').hasClass("blogs") == true){
          blogsjs.init(); 
      }
  });
  </code></pre>
  
  <p><strong>Solution After Feedback</strong></p>
  
  <p>Simply Just used <code>object.method()</code> syntax from within a method to call another method within that same object:</p>
  
  <pre><code>    $(document).ready(function(){
  
      var blogsjs = { 
          init: function(){
              alert("hello from blogs");
              $("input").on('click', function(){
                  $(this).hide('slow', function(){
                     blogsjs.another();
                  });
              });
          },
          another: function(){
              alert("I was called!");
              blogsjs.yetanother();
          },
          yetanother: function(){
               alert("yet another called");   
          }
      };
        blogsjs.init(); 
  
  });
  </code></pre>
  
  <p>I don't like how messy this code looks, but the encapsulation benefits from an Object-oriented design, I think, is solid: Each resource's javascript only has access to the methods inside its javascript object.  </p>