SOURCE

//数组去重
let arrNumber = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
let newArrayNumber = Array.from(new Set(arrNumber))
console.log(newArrayNumber); //[1,2,3,4,5]


//柯里化(Currying)[1]是一种关于函数的高阶技术。它不仅被用于 JavaScript,还被用于其他编程语言。
//柯里化是一种函数的转换,它是指将一个函数从可调用的 f(a, b, c) 转换为可调用的 f(a)(b)(c)。
//柯里化不会调用函数。它只是对函数进行转换。

//柯里化函数作用:1参数复用
//`string` 是模板字符串,ES2015新增的符号。
function uri_curring(protocol) {
    return function (hostname, pathname) {
        return `${protocol}${hostname}${pathname}`
    }
}
const url_https = uri_curring('https://');
const url1 = url_https('1', '1')
const url2 = url_https('2', '2')

//常规任务,浏览器的检测
//确定用户浏览器,从而判断是否支持某种方法
//函数里面嵌套函数
const whichEvent = (function () {
    if (window.addEventListener) {
        //ele表示哪个元素需要添加事件监听;t表示元素需要添加什么类型的事件
        //li就是执行的回调函数;use表示要进行事件冒泡或者事件捕获的选项
        return function (element, type, listener, userCapture) {
            element.addEventListener(type, function (e) {
                listener.call(element, e);
                //call对this进行绑定,并且把原来函数里面隐藏的event对象带入参数里面
            }, userCapture);
        }

    } else if (window.attachEvent) {  
        //执行函数,因为IE支持事件冒泡
        return function (element, type, handler) {
            element.attachEvent('on'+type, function (e) {//on可以统一书写形式的事件类型。
                handler.call(element, e);
                //call对this进行绑定,并且把原来函数里面隐藏的event对象带入参数里面
            });
        }
    }
})();//立即执行函数,放在文件的头部

//2. 延迟执行
function add(){
    let args = Array.prototype.slice.call(arguments);//js把传入到这个函数的全部参数存储在一个叫做arguments的东西里面
    let inner = function () {
        args.push(...arguments);
        return inner
    }
    inner.toString=function(){
        return args.reduce(function(prev,cur){
            return prev + cur;
        });
    };
    return inner;
};

console.log(add(1)(2))
//柯里化(Currying)是把接受多个参数的函数变换成接受一个单一参数(最初函数的第一个参数)的函数,并且返回接受余下的参数且返回结果的新函数的技术。
console 命令行工具 X clear

                    
>
console