Home How to use this call "var res = (fa)(fb)(fc)(fd)()" with args?
Reply: 0

How to use this call "var res = (fa)(fb)(fc)(fd)()" with args?

Jean-Dadet Diasoluka
1#
Jean-Dadet Diasoluka Published in 2018-01-09 10:43:32Z

This kind of call works fine. var res = fa(1)(2)(3)(4);

But I want that each function be called explicitely, like this : var res = (fa)(fb)(fc)(fd)();

How to send args with that kind of call ?

<script type="text/javascript">
  "use strict";
   var fa, fb, fc, fd;  // Noms des fonctions

   fa=function(pa){
      return fb=function(pb){
          return fc=function(pc){
               return fd=function(pd){
                    return pa+pb+pc+pd
                }
           }
      }
   }

/* The following call works fine with args !
var res = fa(1)(2)(3)(4); */

// How to send args with the following call,
// calling each function individualy
// with its parameter, and
// in the same sentence and the same line ?
   var res = (fa)(fb)(fc)(fd)();

   console.log(res);
 </script>

IT SEEMS TO WORK FINE WITH LOCAL VARIABLES ONLY.

<script type="text/javascript">
  "use strict";
   var faL, fbL, fcL, fdL;  // Noms des fonctions

   var faL=function(){
      const La=pa;
      return fbL=function(){
          const Lb=pb;
          return fcL=function(){
               const Lc=pc;
               return fdL=function(){
                    const Ld=pd;
                    return La+Lb+Lc+Ld
                }
           }
      }
   }

// IT SEEMS TO WORK ONLY WIT H LOCAL VARIABLES !
   let pa=1, pb=2, pc=3, pd=4;
   const resL = (faL)(fbL)(fcL)(fdL)();

   console.log(resL);
 </script>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.352979 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO