0

EDIT : This question was marked as duplicate, which is quite unfair.I acknowledge that this question about the question mark answers a part of the question. But the following is still mysterious to me. Thanks a lot !

ORIGINAL QUESTION : I am trying to understand an external script (moment.js) which shows :

! function(a, b) {
    "object" == typeof exports && "undefined" != typeof module 
         ? module.exports = b() 
         : "function" == typeof define && define.amd 
             ? define(b) 
             : a.moment = b()
  }(this, function() {
      "use strict";
      [... folowing code goes here]

I understand the use of a immediately invoked scoping function like :

(function(){[ code here ]})();

And I guess it's about that. Can someone explain to me what is happening here?

CharlYox
  • 34
  • 1
  • 7
  • Also, I'm wondering why the ! before function – CharlYox Feb 23 '18 at 10:41
  • The first function defines the use in AMD or CommonJS, because you can use momentjs with any of this patterns, but of course you need also to work with certain things that are private and others that are public that's the reason the library exposes moment as an object API, without doing pollution of the global object. – juan garcia Feb 23 '18 at 10:45
  • @juangarcia, thanks for your comment; I guess I have to put my nose into AMD and CommonJS then . – CharlYox Feb 27 '18 at 12:13

0 Answers0