zoukankan      html  css  js  c++  java
  • 高阶函数

    高阶函数 指代 参数可以是一个函数,函数中返回函数
    getcallBack(back) {
    return Back();
    }
     
    demo
    // 判断类型 Object.prototype.toString.call();
    function isType(type){ // type == 'boolean'
    return function (obj){
    return Object.prototype.toString.call(obj).includes(type);
    }
    }
    // 包装成一个高阶函数 批量生成函数
    let types = ['String','Object','Array','Null','Undefined','Boolean'];
    let fns = {};
    types.forEach(type=>{ // 批量生成方法
    fns['is'+type] = isType(type)
    })
    let a = '123';
    console.log(fns.isString(a)); // 函数柯里化
     
    我们先声明一个带有 类型的数组 ,遍历数组 ,声明一个对象 ,对象的key  是 数组中 的每一项   fns['is'+type]   数组的value 是函数的返回值  
    sType(type) 会返回一个值 
    Object.prototype.toString.call(obj)  判断函数的类型 
    includes 返回布尔值 
  • 相关阅读:
    leetcode 137
    leetcode 134
    133. Clone Graph
    leetcode 131
    leetcode 130
    mac uwsgi ssl issue handler
    leetcode 85 Maximal Rectangle golang
    leetcode 84 golang
    leetcode 61
    C# 后台实现一次上传多个文件
  • 原文地址:https://www.cnblogs.com/guangzhou11/p/11317707.html
Copyright © 2011-2022 走看看