Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 父参数可以接受子参数吗?_Javascript_Inheritance_Parameters - Fatal编程技术网

Javascript 父参数可以接受子参数吗?

Javascript 父参数可以接受子参数吗?,javascript,inheritance,parameters,Javascript,Inheritance,Parameters,据我所知!cache[str]检查缓存变量是否是包含str参数的数组。这很有意义,因为数组是js中的对象。这本质上是一种定义数组的奇怪方式。fn(str)正在抛开我对代码的其余理解。这是继承的例子还是其他的例子?这是一个(极其简化的)例子,叫做你发布的代码中没有数组。cache变量将对象的引用作为其值。!cache[str]检查是否使用“str”参数中的属性名缓存了值。缓存变量是数组“-nope”cache=Object.create(null)。这与父级、子级、继承或参数无关o[p]只是对象上

据我所知!cache[str]检查缓存变量是否是包含str参数的数组。这很有意义,因为数组是js中的对象。这本质上是一种定义数组的奇怪方式。fn(str)正在抛开我对代码的其余理解。这是继承的例子还是其他的例子?

这是一个(极其简化的)例子,叫做

你发布的代码中没有数组。
cache
变量将对象的引用作为其值。
!cache[str]
检查是否使用“str”参数中的属性名缓存了值。缓存变量是数组“-nope”
cache=Object.create(null)
。这与父级、子级、继承或参数无关
o[p]
只是对象上的一个例子。有人能解释一下等式的fn(str)方面吗?我开始理解对象缓存引用,它只是简单地取str属性名
function cached(fn){

  // Create an object to store the results returned after each function execution.

  const cache = Object.create(null);



  // Returns the wrapped function

  return function cachedFn (str) {



    // If the cache is not hit, the function will be executed

    if ( !cache[str] ) {

        let result = fn(str);



        // Store the result of the function execution in the cache

        cache[str] = result;

    }



    return cache[str]

  }

}