A problem related to currying, [this] .concat ([] .slice.call (arguments)) does not understand this sentence?

topic description

The

function asyncify is a function whose output is the same regardless of whether it is called asynchronously or called by Synchronize (in this case, a = 1). The judgment about Synchronize does not quite understand the logical meaning of it, especially the statement [this] .concat ([] .slice.call (arguments). The book explains that this is called currying, later, which roughly means that parameters can be passed in succession. Later, I still didn"t understand this sentence

.

sources of topics and their own ideas

A case study of the callback chapter in the book "JavaScript you don"t know"

related codes

function asyncify(fn) {
      var orig_fn = fn,
          intv = setTimeout(function () {
                    intv = null;
                    if (fn) fn();
                 }, 0);
      console.log("Wai intv:"+intv);
      fn = null;
      return function () {
        console.log("Nei intv:"+intv);
        if (intv) {
          // 
          fn = orig_fn.bind.apply(
            orig_fn,
            // thisbind(..)
            // currying
            [this].concat([].slice.call(arguments))  
          );
        } else {
          // 
          orig_fn.apply(this, arguments); 
        }
      };
    }
    function result(data) {
      console.log(a); 
    }

    var a = 0;
    var b = asyncify(result);
    aPP;

what result do you expect? What is the error message actually seen?

 1
Apr.09,2021

I guess you are [] .slice.call (arguments) I don't understand here.
arguments is not a real array, but needs to be converted: es5 is written in [] .slice.call (arguments)
ES6: for more information, please see from" call" nofollow noreferrer "> Ruan Yifeng's ES6

.

[1] .concat ([2p3]) array join operation, this is easy to understand


 fn = orig_fn.bind.apply(
            orig_fn,
            [this].concat([].slice.call(arguments))  
          );

first of all, in order to meet the requirements, newResult of the new function created by asyncify (result); is of course always useful for one-time creation, so there will be orig_fn.bind , and the first parameter of bind is of course this , so the result I want is orig_fn.bind (this,arg1,agr2) , so how to do it? naturally, it's apply , and there's nothing left.


arguments is an array set of all parameters in the function, which can be accessed with subscript. [] .slice.call (arguments) this is the slice method that argument calls the array. [this] .concat ([] .slice.call (arguments)) means slice before concat

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e12b-2c3f9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e12b-2c3f9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?