这个JavaScript程序采取了哪些步骤

mjm*_*che 1 javascript

有人可以解释一下这个程序采取的步骤以及它们被采取的顺序,以便产生"假"的结果

function negate(func) {
  return function(x) {
    return !func(x);
  };
}
var isNotNaN = negate(isNaN);
show(isNotNaN(NaN));
Run Code Online (Sandbox Code Playgroud)

use*_*716 8

  // 1. A function called "negate is declared
function negate(func) {  // 3. The "isNaN" function is received by negate().

  return function(x) {   // 4. A function is returned from the negate() call
    return !func(x);     //     that invokes the "isNaN" function, and returns
  };                     //     the logical opposite of its return value.

}

                  // 2. The built in "isNaN" function is passed to negate()
var isNotNaN = negate(isNaN);
 // 5. The function returned from negate() is assigned to the "isNotNaN" variable

         // 6. The "isNotNaN" function is invoked, and passed the "NaN" value.
show(isNotNaN(NaN));
 // 7. The result returned from "isNotNaN" is passed to the show() function.
Run Code Online (Sandbox Code Playgroud)

最终结果是你有一个函数返回函数的反面isNaN.

好像矫枉过正时,你可以打电话isNaN!自己.

show( !isNaN(NaN) );  // gives the same result
Run Code Online (Sandbox Code Playgroud)