zoukankan      html  css  js  c++  java
  • 201707271123_《Javascript的‘缓存’》

    function memoizeFunction(func) {
        var cache = {};
        return function() {
            var key = arguments[0];
            if (cache[key]) {
                return cache[key];
            } else {
                var val = func.apply(this, arguments);
                cache[key] = val;
                return val;
            }
        };
    };
    
    function add(x,y){
       var result = 0;
    	this.x = x;
        this.y = y;
        result = this.x + this.y
        console.log(result);
    };
    
    memoizeFunction(add(19,3)); //22
    
    memoizeFunction(add(19,3)); //还是22, 但从缓存中读取,速度快
    

      

  • 相关阅读:
    元组类型
    字符串类型
    列表类型
    python 循环
    python语句
    python运算符
    python1
    软件管理
    rpm yum
    LVM
  • 原文地址:https://www.cnblogs.com/beesky520/p/7243889.html
Copyright © 2011-2022 走看看