How do I override a JQuery (Datatable RowGroup) library function?

509
February 13, 2020, at 04:30 AM

I'm rather new to Javascript, and the scoping syntax definitely confuses me when looking at open source libraries especially when it has a lot of advanced concepts like closure, anonymous functions, etc. The Jquery Datatables RowGroup is a a bit buggy with Responsiveness, so I took the bold attempt of writing my own attempt at a solution.

Below is the relevant snippet from the RowGroup library, source code from https://cdn.datatables.net/rowgroup/1.1.1/js/dataTables.rowGroup.js:

/** <Not sure what is going on here!> */
(function (factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD
        define(['jquery', 'datatables.net'], function ($) {
            return factory($, window, document);
        });
    } else if (typeof exports === 'object') {
        // CommonJS
        module.exports = function (root, $) {
            if (!root) {
                root = window;
            }
            if (!$ || !$.fn.dataTable) {
                $ = require('datatables.net')(root, $).$;
            }
            return factory($, root, root.document);
        };
    } else {
        // Browser
        factory(jQuery, window, document);
    }
}(function ($, window, document, undefined) {
    /** </Not sure what is going on here!> */
    'use strict';
    var DataTable = $.fn.dataTable;
    var RowGroup = function (dt, opts) {
        //...
    };
    $.extend(RowGroup.prototype, {
        //...
        _constructor: function () {
            //...
            dt.on('responsive-resize.dt', function () {
                that._adjustColspan();
            });
        },
        /** I would like to override this function, externally */
        _adjustColspan: function () {
            @ @override
        }
    });
}));

Although it is open source, instead of modifying the library directly, I'd like to override the function _adjustColspan from a separate Javascript file (which will be included after this library). This will allow the library still be update-able without hassle, and any custom changes can be easily tracked.

So I'm looking some clarification on:

  1. What is this factory code above doing?
  2. What is the scope of the _adjustColspan function? (From what I understand, not all functions are accessible, so what I'm trying to do might not even be possible to begin with - if it's a private function)
  3. And lastly, my main question, if _adjustColspan is not a private function, how do I go about overriding it in an external .js? It does not appear to be part of the Window / global scope.
READ ALSO
How to fix 401 after attempt to override existing POST?

How to fix 401 after attempt to override existing POST?

I'm receiving 401 error when trying to override existing POST with new dataIt throws 401

3268
Dynamic Object Reference in Object.keys(obj) [duplicate]

Dynamic Object Reference in Object.keys(obj) [duplicate]

How can I iterate through an ObjectKeys(obj) where the obj might change (and thus need to be a variable that changes)?

475
Accessing A Block By Clicking A Button

Accessing A Block By Clicking A Button

I have a form in my webpage and I have created a button in the footer area of my pageI wants if anyone clicks this button then they will go to the contact form which is located on the top of my page

476
Altering element&#39;s content in javascript

Altering element's content in javascript

which is advisableto use?setContent or

437