0

I want to modify code to select only parts that I need. But the code seems wired and I can't find out what is going on there. it's a 16000 line of code and I can't put it here. I just need a hand to figure out why functions are separated using , sign?

}, o.r = function(e) {

why we have such structure like :

 }([function(e, t, n) {

Here is the code:

! function(n) {
    var i = {};

    function o(e) {
        if (i[e]) return i[e].exports;
        var t = i[e] = {
            i: e,
            l: !1,
            exports: {}
        };
        return n[e].call(t.exports, t, t.exports, o), t.l = !0, t.exports
    }
    o.m = n, o.c = i, o.d = function(e, t, n) {
        o.o(e, t) || Object.defineProperty(e, t, {
            enumerable: !0,
            get: n
        })
    }, o.r = function(e) {
        "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, {
            value: "Module"
        }), Object.defineProperty(e, "__esModule", {
            value: !0
        })
    }, o.t = function(t, e) {
        if (1 & e && (t = o(t)), 8 & e) return t;
        if (4 & e && "object" == typeof t && t && t.__esModule) return t;
        var n = Object.create(null);
        if (o.r(n), Object.defineProperty(n, "default", {
                enumerable: !0,
                value: t
            }), 2 & e && "string" != typeof t)
            for (var i in t) o.d(n, i, function(e) {
                return t[e]
            }.bind(null, i));
        return n
    }, o.n = function(e) {
        var t = e && e.__esModule ? function() {
            return e.default
        } : function() {
            return e
        };
        return o.d(t, "a", t), t
    }, o.o = function(e, t) {
        return Object.prototype.hasOwnProperty.call(e, t)
    }, o.p = "", o(o.s = 0)
}([function(e, t, n) {
    n(1), n(12), n(14), n(15), n(17), n(20), n(53), n(56), n(58), n(60), n(63), n(65), n(67)
}, function(e, t, n) {
    n(2), n(10), n(11)
}, function(e, t, n) {
    var i, o, r;
    window.$ = window.jQuery = n(3), window.Popper = n(4), n(6), window.SmoothScroll = n(8), n(9), i = jQuery, o = window, r = {
        name: "TheSaaS",
        version: "2.1.8",
        vendors: [],
        body: i("body"),
        navbar: i(".navbar"),
        header: i(".header"),
        footer: i(".footer"),
        defaults: {
            googleApiKey: null,
            googleAnalyticsKey: null,
            reCaptchaSiteKey: null,
            reCaptchaLanguage: null,
            disableAOSonMobile: !0,
            smoothScroll: !1
        },
        init: function() {
            r.initVendors(), r.initBind(), r.initDrawer(), r.initFont(), r.initForm(), r.initMailer(), r.initModal(), r.initNavbar(), r.initOffcanvas(), r.initPopup(), r.initScroll(), r.initSection(), r.initSidebar(), r.initVideo(), i('[data-provide="anchor"]').each(function() {
                var e = i(this);
                e.append('<a class="anchor" href="#' + e.attr("id") + '"></a>')
            })
        },
        initVendors: function() {
            r.vendors.forEach(function(e) {
                var t = o.page["init" + e];
                "function" == typeof t && t()
            })
        },
        registerVendor: function(e) {
            r.vendors.push(e)
        }
    }, o.page = r, $(function() {})
}, function(an, ln, e) {
    var cn;

  .... and code goes down ....

UPDATE:

How can I remove one of the functions in the simplified structure below:

... }, function(e, t, n) {

}, function(e, t, n) {

}, function(e, t, n) {

}, function(e, t) {

}, ...
foxer
  • 811
  • 1
  • 6
  • 16
  • It's an [IIFE](https://stackoverflow.com/questions/3755606/what-does-the-exclamation-mark-do-before-the-function) that accepts another function as a parameter. Everything is minified, though, hence the "weirdness". In particular this might be a minified version of [the pattern to ensure `$` is jQuery using an IIFE](https://stackoverflow.com/questions/4983150/jquery-dollar-sign-as-function-argument). The `! function(n) {` is likely a minified version of `(function($) {` while `}([function(e, t, n)` is likely `}(jQuery)` – VLAZ Jun 13 '20 at 08:25

1 Answers1

1

I just need a hand to figure out why functions are separated using , sign?

There's no good reason for it in that example, ; would have been just fine.

The comma operator is one of JavaScript's more unusual operators: It evaluates its left-hand operand, then throws away the resulting value and evaluates its right-hand operand, then takes that value as its result. The code you've shown has:

o.m = n, o.c = i, o.d = function(e, t, n) {
    // ...
}, o.r = function(e) {
    // ...
},

...and so on. Each of those (o.m = n, o.c = i, etc.) is an assignment expression separated from the next assignment expression by the comma operator, so they get done in order.

That code could just as easily have been:

o.m = n;
o.c = i;
o.d = function(e, t, n) {
    // ...
};
o.r = function(e) {
    // ...
};

...and so on. But the minifier that was applied to that code used , instead.

The other context where you see this is when it starts with a declaration, like:

var a = x, b = y, c = z, // ...

In that context it's not the comma operator, it's just a declaration with multiple things being declared, but it does something similar: declares and then initializes each of those variables (in order).


How can I remove one of the functions in the simplified structure below...

Remove the function expression for the function you want to remove, and the comma before or after it. For instance, to remove the second one:

    ... }, function(e, t, n) {
    }, function(e, t, n) {
//     ^−−−−−−−−−−−−−−−−−−−−−−− function expression starts here
    }, function(e, t, n) {
//  ^−−−−−−−−−−−−−−−−−−−−−−− function expression ends here
    }, function(e, t) {
    }, ...

So:

    ... }, function(e, t, n) {
    }, function(e, t, n) {
    }, function(e, t) {
    }, ...
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Thanks for the answer plus one... if you could add an answer for the updated part of the question it'll be accepted as the correct one... – foxer Jun 13 '20 at 11:01