A problem of function parameter .arg

function __matchArgs__(fn) {
    return function (...args) {
        console.log(args)
        if (args.length !== fn.length) {
            throw RangeError("Arguments not match!");
        }
        return fn.apply(this, args);
    }
}

var add = __matchArgs__((a, b, c) => a + b + c);

console.log(add(1, 2, 3));

I would like to ask return function (. ARGs) shouldn"t the arg here be the formal argument of the function _ _ matchArgs__? Why does log come out as a formal parameter in fn?

Mar.31,2021

matchArgs the formal parameter fn, function returns an anonymous function with its own indefinite parameters. The formal parameters of the function are determined at the time of definition, and are independent of each other ~


.

it is obvious when it is written like this:

function __matchArgs__(fn) {

  function returnFn(...args) {
    console.log(args)
    if (args.length !== fn.length) {
      throw RangeError('Arguments not match!');
    }
    return fn.apply(this, args);
  }
  return returnFn
}

you just "incidentally" defined this function in return, which is essentially a separate function. For the parameter part of a function, the parameter part does not have any connection with the external scope without using the default parameter

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-1b3a637-2b988.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-1b3a637-2b988.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?