Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.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
JS:JavaScript中的混合插件和缓存?这是怎么回事?_Javascript_Node.js_Caching - Fatal编程技术网

JS:JavaScript中的混合插件和缓存?这是怎么回事?

JS:JavaScript中的混合插件和缓存?这是怎么回事?,javascript,node.js,caching,Javascript,Node.js,Caching,所以 我是新手JS开发者 混搭: 当我经历 我无法理解主题3(带选项)和主题4(添加缓存)之间的区别 引用“因此,您可能担心这种方法会产生额外的性能开销,因为我们在每次调用中都重新定义相同的函数。”(添加缓存下的第一段) 问题: 如上所述,为什么每次都要重新定义函数 缓存是如何实现的 调用()在这里做什么 如博客所述,这如何提高性能 附:我使用Node.js运行代码——因此全局(this)打印了节点的全局this var asRectangle = (function () { co

所以

我是新手JS开发者

混搭:

当我经历

我无法理解主题3(带选项)和主题4(添加缓存)之间的区别

引用“因此,您可能担心这种方法会产生额外的性能开销,因为我们在每次调用中都重新定义相同的函数。”(添加缓存下的第一段)

问题:

  • 如上所述,为什么每次都要重新定义函数
  • 缓存是如何实现的
  • 调用()在这里做什么
  • 如博客所述,这如何提高性能
  • 附:我使用Node.js运行代码——因此全局(this)打印了节点的全局this

    var asRectangle = (function () {
    
        console.log(this) // global this 
    
        function area() {
            console.log(this); // {length : 1, width: 2}
            return this.length * this.width
        }
    
        function grow() {
            this.length++;
            this.width++;
        }
    
        function shrink() {
            this.length--;
            this.width--;
        }
    
        return function () {
            this.area = area;
            this.grow = grow;
            this.shrink = shrink;
            return this;
        };
    
    })();
    
    
    var React = function (len, wid) {
        this.length = len;
        this.width = wid;
    }
    
    asRectangle.call(React.prototype); // What is the use of this?
    
    var react = new React(1, 2);
    
    react.area();