if-statements can add serious complexity and beg for refactoring. You can use polymorphic functions to simplify your ifs and dynamically call the appropriate method. For example you have the code like: function charge(){ if(this.moive.type==="regular…
1. 介绍 第一眼看到ES6新增加的 arrow function 时,感觉非常像 lambda 表达式. 那么arrow function是干什么的呢?可以看作为匿名函数的简写方式. 如: var addition = function(a, b) { return a + b }; // 等同 var addition = (a, b) => { return a + b }; 2. 语法 arrow functions(箭头函数)主要有以下4种语法: // 1)基本 (param1, pa…
In this lesson you will create a utility function that allows you to quickly compose behavior of multiple functions to create new behavior. By the end, you will have successfully created a tremendously popular helper function that is used in JavaScri…
索引 Notes 高阶函数 forEach filter map reduce some findIndex 重写课本示例代码 Excercises Flattening Your own loop Everything Dominant writing direction Notes 1.高阶函数的概念:Functions that operate on other functions, either by taking them as arguments or by returning th…
We can dot-chain our way to great success with an instance of Maybe, but there are probably cases where you need to apply the same series of transformations against different Maybes. In this lesson, we’ll look at some point-free versions of some comm…
This can be handy if you have a rate limit on API requests or if you need to pass the result of each promise to the next one. function fetchMessages(username) { return fetch(`https://example.com/api/messages/${username}`) .then(response => response.j…