首页 > 解决方案 > 如何在 module.exports 中调用多个函数

问题描述

我有一个单独的 js 文件中的函数列表。需要在 node.js 中调用整个文件。这些函数负责创建 j3pop 标头。代码如下所示:

(function1{}())
(function2{}())
(function3{}())

如何将它们全部导出并按顺序调用?

这就是我在文件中获得第三个函数的方式:

module.exports = {   (function() {
      'use strict';
      console.log("inside");
      var afterReadyCbCalled = false;
      var originalHeaders = ["X-Origin-DC", "gytp","Cache-Control", "max-age=0","X-Forwarded-For", "103.255.4.53","X-Client-SrcPort", "45244","Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","Accept-Language", "en-US,en;q=0.5","X-Forwarded-Proto", "https","X-TLS-Version", "771","Upgrade-Insecure-Requests", "1","ISTL-REFERER", "https://www.sahibinden.com/",];
      var originalBody = "";
      function afterReadyCb() {
        if (afterReadyCbCalled) return;
        afterReadyCbCalled = true;
        var xhr = new XMLHttpRequest();
        xhr.onload = function() {
          var isValid = xhr.getResponseHeader("ISTL-INFINITE-LOOP");
          if (isValid != null && isValid != '') return;
          var a = xhr.getResponseHeader("ISTL-REDIRECT-TO");
          if (a != null && a != '') {
            location.replace(a);
          } else {
            if (window.history != null && typeof history.replaceState === 'function') {
              var responseURL = xhr.responseURL != null ? xhr.responseURL : xhr.getResponseHeader("ISTL-RESPONSE-URL");
              if (responseURL != null && responseURL != '') {
                history.replaceState(null, '', responseURL);
              }
            }
            document.open();
            document.write(xhr.responseText);
            document.close();
          }
        };
        xhr.open("get", location.href, true);
        for (var i = 0; i < originalHeaders.length; i += 2) {
          var headerName = originalHeaders[i];
          try {
            xhr.setRequestHeader(headerName, originalHeaders[i + 1]);
          } catch (e) {}
        }
        xhr.setRequestHeader("ISTL-INFINITE-LOOP", '1');
        xhr.send(originalBody);
        var evt = document.createEvent('Event');
        evt.initEvent('QLpZFJdHv', true, true);
        dispatchEvent(evt);
      }
      addEventListener('afterReady', afterReadyCb, false);
      setTimeout(afterReadyCb, 400);
    }());

 }

不知道休息

标签: javascriptnode.js

解决方案


会不会只是:

module.exports = {
    (function() {
        (function() {})()
        (function() {})()
        (function() {})()
    })()
}

推荐阅读