すたらSample

(jQuery) The test of dividing JavaScript files.

2012/02/04

Please click following button.

<head>

<script type="text/javascript" src="divide01.js"></script>
<script type="text/javascript" src="divide02.js"></script>
<script type="text/javascript" src="divide03.js"></script>

<script type="text/javascript">
  jQuery(document).ready(function($) {
    $('#btn').testDivide('#msg');
  });
</script>

divide01.js

(function($) {
  var obj = {
    main : function(elem){
      $(this).click(function(){
        $(elem).text(obj.title + ' ' + obj.count);
        obj.count++;
      });
    }
  };
  $.fn.extend({testDivide : obj});
})(jQuery);

divide02.js

(function($) {
  var obj = {
    title  : 'count:'
  };
  $.extend($.fn.testDivide, obj);
})(jQuery);

divide03.js

(function($) {
  var obj = {
    count  : 0
  };
  $.extend($.fn.testDivide, obj);
  var merged = $.fn.testDivide;
  $.fn.extend({testDivide : merged.main});
})(jQuery);