1

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);
Ernest Appiah
  • 133
  • 2
  • 13
  • Possible duplicate of [Why use NOT operator on anonymous function call? (a la Knockout 2.1.0)](https://stackoverflow.com/questions/11915957/why-use-not-operator-on-anonymous-function-call-a-la-knockout-2-1-0) – rrk Sep 19 '17 at 06:36
  • Thanks, l read the link you gave, l have removed the part where the link explains and clearly understand. However, the above question is not a duplicate. Thanks for the link – Ernest Appiah Sep 19 '17 at 06:38

0 Answers0