es6 curry function


// vuex getters export const getAdsFilterConfig = (state) => (spreader) => {
console.log('state =', state)
console.log('spreader =', spreader)
return state[spreader];
}; // this.getAdsFilterConfig(this.spreaderAlias);
// export const stateActivity = state => state.stateActivity;

equal to

// getter 自动执行,getter func ===  func()

export const getAdsFilterConfig = (state) => {
// state 来自 store 上下文
return (spreader) => {
return state[spreader];
};
}

https://codesandbox.io/s/vuex-store-getter-es6-curry-function-n7prr?file=/src/main.js

bug

state = {k: 1};
// {k: 1} getAdsFilterConfig = (state) => (spreader) => {
return state[spreader];
};
/*
(state) => (spreader) => {
return state[spreader];
}
*/
getAdsFilterConfig(`k`);
/*
(spreader) => {
return state[spreader];
}
*/ getAdsFilterConfig()(`k`);
// Uncaught TypeError: Cannot read property 'k' of undefined

vuex

const store = new Vuex.Store({
state: {
todos: [
{ id: 1, text: '...', done: true },
{ id: 2, text: '...', done: false }
]
},
getters: {
doneTodos: state => {
return state.todos.filter(todo => todo.done)
}
}
})

https://vuex.vuejs.org/guide/getters.html#method-style-access

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


es6 curry function的更多相关文章

  1. vue & lifecycle methods & this bug & ES6 Arrow function & this bind bug

    vue & lifecycle methods & this bug ES6 Arrow function & this bind bug bad fetchTableData ...

  2. ES6 Arrow Function & this bug

    ES6 Arrow Function & this bug let accHeadings = document.querySelectorAll(`.accordionItemHeading ...

  3. ES6 Arrow Function All In One

    ES6 Arrow Function All In One this const log = console.log; const arrow_func = (args) => log(`arg ...

  4. ES6 arrow function vs ES5 function

    ES6 arrow function vs ES5 function ES6 arrow function 与 ES5 function 区别 this refs xgqfrms 2012-2020 ...

  5. ES6 Arrow Function return Object

    ES6 Arrow Function return Object https://github.com/lydiahallie/javascript-questions/issues/220#issu ...

  6. ES6 arrow function

    语法: () => { … } // 零个参数用 () 表示: x => { … } // 一个参数可以省略 (): (x, y) => { … } // 多参数不能省略 (): 当 ...

  7. JavaScript- The Good Parts function Curry

    Functions are values, and we can manipulate function values in interesting ways.Currying allows us t ...

  8. Function Programming - 柯里化(curry)

    看到一篇非常不错的文章,这里分享给大家:http://www.jianshu.com/p/fa3568087881. 首先,柯里化的定义:你可以只透过部分的参数呼叫一个function,它会回传一个f ...

  9. [ES6] 06. Arrow Function =>

    ES6 arrow function is somehow like CoffeeScirpt. CoffeeScript: //function call coffee = -> coffee ...

随机推荐

  1. 阿里云 CentOS7中搭建FTP服务器

    1配置 vsftpd-3.0.2-27.el7.x86_64 阿里云 centos 7.0 2 ftp工作模式 2.1 ftp通道 ftp工作会启动两个通道: 控制通道,数据通道 在ftp协议中,控制 ...

  2. C++ Primer Plus读书笔记(八)函数探幽

    1.内联函数 inline int square(x) {return x*x} 2.引用变量 int& 中的& 不是地址运算符,就想定义指针时的char* 一样,int&指的 ...

  3. tricks - 实现

    笔记总页面 目录 负下标 动态开点 花括号 负下标 有的时候我们需要存一些负的东西,比如我就只要一个 \(-1\),或者说值域是 \([-10^6,10^6]\),而我懒得写平移 (写平移不仅麻烦,而 ...

  4. java关键字static使用总结

    java关键字static使用总结 1.static修饰的方法被称之为静态方法也叫做类方法,加static的方法,可以通过类名直接访问,不加static的方法只能通过对象名访问. 静态方法可以直接通过 ...

  5. Web漏洞扫描-AWVS

    Web漏洞扫描-AWVS 一.AWVS概述 二.功能以及特点 三.AWVS界面 四.AWVS使用 相关优质博文: CSDN:帽子不够白:WEB渗透测试之三大漏扫神器 一.AWVS概述 Acunetix ...

  6. Spring Boot项目application.yml文件数据库配置密码加密

    在Spring boot开发中,需要在application.yml文件里配置数据库的连接信息,或者在启动时传入数据库密码,如果不加密,传明文,数据库就直接暴露了,相当于"裸奔"了 ...

  7. checkbox限制选中个数

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  8. SQL系列总结——基础篇(一)

       数据库与表.列的关系其实就像是一个Excel工作薄(workbook)与Excel表格(sheet)以及表格中的列的关系一样.关系数据库中最基本的对象有3个:表.列.用户     基本的概念名词 ...

  9. 如何用RabbitMQ实现延迟队列

    前言 在 jdk 的 juc 工具包中,提供了一种延迟队列 DelayQueue.延迟队列用处非常广泛,比如我们最常见的场景就是在网购或者外卖平台中发起一个订单,如果不付款,一般 15 分钟后就会被关 ...

  10. 牛客练习赛53 E-老瞎眼pk小鲜肉(思维+线段树+离线)

    前言 听说是线段树离线查询?? 做题做着做着慢慢对离线操作有点感觉了,不过也还没参透,等再做些题目再来讨论离线.在线操作. 这题赛后看代码发现有人用的树状数组,$tql$.当然能用树状数组写的线段树也 ...