如何在module.exports中调用多个函数

时间:2020-06-03 12:20:02

标签: javascript node.js

我有一个单独的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);
    }());

 }

不知道休息

2 个答案:

答案 0 :(得分:0)

会只是:

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

答案 1 :(得分:0)

您可以通过执行以下操作在module.exports中调用多个功能;

module.exports = {
   somefunction1,
   somefunction2,
   somefunction3,
}

function somefunction1(){
   // do stuffs
}
function somefunction2(){
   // do stuffs
}
function somefunction3(){
   // do stuffs
}

然后导入另一个文件中;

const anyName = require('./theFilePath');

anyName.somefunction1()