title: I am not able to access object function using variable name?
body: <p>I am beginner to Javascript, Trying to access object function using variable name but its giving some error. this is just dummy code if some one can correct me what I am doing worng here.. What is best method to do it.</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;  
          &lt;title&gt;Pub/Sub Test&lt;/title&gt; 
      &lt;/head&gt;
      &lt;body&gt;  
          &lt;div id="wrap1" data-components="tooltip"&gt;
              &lt;p&gt;&lt;h1&gt;pubsubz Test&lt;/h1&gt;
              &lt;p&gt;Run with Firebug or a console simulator open.&lt;/p&gt;&lt;/p&gt;
          &lt;/div&gt;
          &lt;div id="wrap2" data-components="tooltip"&gt;
              &lt;p&gt;&lt;h1&gt;pubsubz Test&lt;/h1&gt;
              &lt;p&gt;Run with Firebug or a console simulator open.&lt;/p&gt;&lt;/p&gt;
          &lt;/div&gt;
          &lt;div id="wrap3" data-components="tooltip"&gt;
              &lt;p&gt;&lt;h1&gt;pubsubz Test&lt;/h1&gt;
              &lt;p&gt;Run with Firebug or a console simulator open.&lt;/p&gt;&lt;/p&gt;
          &lt;/div&gt;
  
          &lt;script type="text/javascript" src="jquery-1.6.4.min.js"&gt;&lt;/script&gt;
  
          &lt;script&gt;
              var r=r||{};
              (function(tooltip,$,w,d,undefined){
                  var pos,
                  attr="data-options",
                  defaultSetting = {
                      horizontal : true,
                      vertical : "above"
                  };
                  tooltip.init = function($el){
                      alert("hello");
                  }
              })(r.tooltip = r.tooltip || {},jQuery,window,document);
  
              (function(r,$){
                  var els = {
                      $body : $('body')
                  };
                  // identify modules
                  var $modules = els.$body.find('[data-components]');
                  // create queue from modules
                  $modules.each(function(i,v){
                      var $module=$(this).data('components'); //value = tooltip
                      //want to excute r.tooltip.init() function but there is some error - $module contain value tooltip
                      r.$module.init();
                  });
              })(r=r||{},jQuery);
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>