Can someone clearly explain the following functions for me? More importantly, within each function which nested function get called first? I have read couple of tutorials online, and l managed to identify the following while going through some open source projects.
Function 1
  (function (factory) {
      if (typeof define === 'function' && define.amd) {
        define(['jquery'], factory);
      } else if (typeof exports === 'object') {
        factory(require('jquery'));
      } else {
        factory(jQuery);
      }
    })(function ($) {
      function Avatar($element) {
         this.init();
        }
       Avatar.prototype = {
         constructor: Avatar,
           init: function () {
            }
         };
        $(function () {
          return new Avatar($('#avatar'));
      });
    });
Function 2
!function($) {
    "use strict";
    var Nestable = function() {};
    Nestable.prototype.updateOutput = function (e) { },
    Nestable.prototype.init = function() { },
    $.Nestable = new Nestable, $.Nestable.Constructor = Nestable
}(window.jQuery),
function($) {
    "use strict";
    $.Nestable.init()
}(window.jQuery);
