-1

I'm trying to understand what the following function returns:

fs.api.services.wrapOnSuccess_ = function(a, b, c) {
    if (b) return c = c || function() {},
        function(d, e, f) {
            fs.isDefinedAndNotNull(d.debugtrace) && fs.api.services.handleDebugTrace_(d.debugtrace);
            200 == d.meta.code ? (fs.api.getLogger().debug("success"),
                b(a(d.response), fs.api.services.rawBundleSuccess_(d, e, f))) :
            (fs.api.getLogger().error("non 200 meta code on api response", d), c(d.meta, fs.api.services.rawBundleSuccess_(d, e, f)))
        }

Is it right that it returns a ternary function since function(d,e,f){..} is on the right of the comma? If so, does it mean calls to wrapOnSuccess_ should look something like wrapOnSuccess_(x,y,z)(s,t,u)?

John M.
  • 2,338
  • 4
  • 19
  • 41
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator – Dexygen Nov 25 '17 at 01:13
  • 3
    Possible duplicate of [What does a comma do in JavaScript expressions?](https://stackoverflow.com/questions/3561043/what-does-a-comma-do-in-javascript-expressions) – Dexygen Nov 25 '17 at 01:14

1 Answers1

0

This is minified code. It's not really meant to be understood in the typical sense.

As far as what it returns, if b is truthy, it'll return the function(d, e, f) { function after assigning either c to c if c was truthy, else the no-op function, to c.

So yes, you could invoke the return value immediately if b was truthy`. Looks like we're missing the rest of the function though.

Keep in mind that the comma operator has the lowest precedence of all operators. That should help figure things out.

  • https://stackoverflow.com/questions/3561043/what-does-a-comma-do-in-javascript-expressions. – Danny Fardy Jhonston Bermúdez Nov 25 '17 at 01:16
  • @DannyFardyJhonstonBermúdez: The OP is asking specifically how it impacts the given function. The operations after the `return` are convoluted, so they weren't sure what exactly was returned. –  Nov 25 '17 at 01:18