Convert a jQuery plugin into function and move inside existing JavaScript object
<p>Below I have the basic structure for a JavaScript project and below that is a small jQuery plugin library.</p>

<p>My goal is to basically integrate the bottom jQuery plugin into my JavaScript project below.</p>

<p>In the project code below the jQuery plugin is called inside the <code>get_social_counts</code> function.  IF the jQuery plugin could be converted into a regular function and put into the project then the call to it inside of <code>get_social_counts</code> could be updated to simply call a function from the same object.</p>

<p>I am not sure how to integrate the jQuery plugin into my code though any help appreciated.</p>

<p><strong>JS library</strong></p>

<pre><code>var SocialShareButtons = {

  init: function() {
    this.getPageDataToShare();
    this.build_social_btn_html();
    this.buildShareWindow();
  },

  get_social_counts: function(thisUrl) {

            $('.sharedCount .count').countTo({
                from: 0,
                to: totalCount,
                speed: 1000,
                refreshInterval: 5,
                formatter: function (value, options) {
                    return value.toFixed(options.decimals);
                },
            });

  },

  ////////////// several other functions.......

}
</code></pre>

<p><strong>jQuery Plugin</strong></p>

<pre><code>  $.fn.countTo = function (options) {
    options = options || {};

    return $(this).each(function () {
      // set options for current element
      var settings = $.extend({}, $.fn.countTo.defaults, {
        from:            $(this).data('from'),
        to:              $(this).data('to'),
        speed:           $(this).data('speed'),
        refreshInterval: $(this).data('refresh-interval'),
        decimals:        $(this).data('decimals')
      }, options);

      // how many times to update the value, and how much to increment the value on each update
      var loops = Math.ceil(settings.speed / settings.refreshInterval),
        increment = (settings.to - settings.from) / loops;

      // references &amp; variables that will change with each update
      var self = this,
        $self = $(this),
        loopCount = 0,
        value = settings.from,
        data = $self.data('countTo') || {};

      $self.data('countTo', data);

      // if an existing interval can be found, clear it first
      if (data.interval) {
        clearInterval(data.interval);
      }
      data.interval = setInterval(updateTimer, settings.refreshInterval);

      // initialize the element with the starting value
      render(value);

      function updateTimer() {
        value += increment;
        loopCount++;

        render(value);

        if (typeof(settings.onUpdate) == 'function') {
          settings.onUpdate.call(self, value);
        }

        if (loopCount &gt;= loops) {
          // remove the interval
          $self.removeData('countTo');
          clearInterval(data.interval);
          value = settings.to;

          if (typeof(settings.onComplete) == 'function') {
            settings.onComplete.call(self, value);
          }
        }
      }

      function render(value) {
        var formattedValue = settings.formatter.call(self, value, settings);
        $self.text(formattedValue);
      }
    });
  };

  $.fn.countTo.defaults = {
    from: 0,               // the number the element should start at
    to: 0,                 // the number the element should end at
    speed: 1000,           // how long it should take to count between the target numbers
    refreshInterval: 100,  // how often the element should be updated
    decimals: 0,           // the number of decimal places to show
    formatter: formatter,  // handler for formatting the value before rendering
    onUpdate: null,        // callback method for every time the element is updated
    onComplete: null       // callback method for when the element finishes updating
  };

  function formatter(value, settings) {
    return value.toFixed(settings.decimals);
  }
}(jQuery));
</code></pre>