0

I'm working with a fork of an open source project that is a Node.JS app. Given the code below, what does the first parenthetical expression do when it comes to executing the .onNetwork() method call attached to the second parenthetical expression? I have never seen this style of Javascript call before and I'm not sure how to parse it to form the correct execution model in my head.

I'm referring to this line to this line from the code shown below:

(0, _ControllerFor2.default)(packageFileName).onNetwork(Network, txParams, networkFileName);

I have never seen two parenthetical expression in a row preceded a method call. To be specific, I'm breaking the line above down as:

  • First parenthetical expression: (0, _ControllerFor2.default)

  • Second parenthetical expression: (packageFileName)

  • Method call: .onNetwork(Network, txParams, networkFileName)

If someone could explain what happens with each part of this line referring to the three parts I have labeled above, and describe what really happens with the .onNetwork() method as a result, that would be very helpful. Links to the appropriate Javascript language pages that describe these constructs would be appreciated too since I'm not sure how to describe them during a web search.

Open source GitHub repo the code is from:

https://github.com/zeppelinos/zos-cli

Host Javascript source file "scripts/push.js":

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _ControllerFor = require("../models/local/ControllerFor");

var _ControllerFor2 = _interopRequireDefault(_ControllerFor);

var _stdout = require("../utils/stdout");

var _stdout2 = _interopRequireDefault(_stdout);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = async function push({ network, deployStdlib, reupload = false, txParams = {}, packageFileName = undefined, networkFileName = undefined }) {
  // This is the line I am referring to in the text above.
  const appController = (0, _ControllerFor2.default)(packageFileName).onNetwork(network, txParams, networkFileName);

  try {
    if (deployStdlib && !appController.isLib()) {
      await appController.deployStdlib();
    }
    await appController.push(reupload);
    (0, _stdout2.default)(appController.isLib() ? appController.packageAddress : appController.appAddress);
  } finally {
    appController.writeNetworkPackage();
  }
};
Robert Oschler
  • 14,153
  • 18
  • 94
  • 227
  • @Barmar Thank you for that excellent link. As far as the duplicate nature of my post please consider this. If people don't know that Babel is the reason for that construct appearing, like I didn't, they will never find the question that you linked to (I didn't until you found it for me). I agree that post answers my question, but I feel you'll be doing other non-Babel literate people a disservice by removing mine because frequently the specific structure or syntax of a question is what helps people find the right answer and not the answer itself. Your call of course – Robert Oschler Jun 12 '18 at 05:54
  • Actually, I found that question and several other similar ones by searching for `[javascript] zero comma`. They're not all about Babel, but that one appears to have the clearest explanation, so I chose it as the duplicate. I'm not sure what you mean about removing yours -- duplicates aren't automatically removed. – Barmar Jun 12 '18 at 17:19
  • @Barmar "duplicates aren't automatically removed". I didn't know that, thanks. I thought they were. – Robert Oschler Jun 12 '18 at 17:44

0 Answers0