Open gracekrcx opened 3 years ago
var add = function(x) {
return function(y) {
return x + y;
};
};
var s1 = add(1); // 策略 1
var s10 = add(10); // 策略 10
s1(2); // data 2
s10(20) // data 20
const { curry } = require('ramda')
const getKey = curry((key, obj)=>{
return obj[key]
})
const getName = getKey("name") // 策略
const getEmial = getKey("email") // 策略
const getKey = ((key)=>{
return (obj)=>{
return obj[key]
}
})
const getName = getKey('name') // 策略
const names = [
{name: 'Bob', age: 13},
{name: 'Zoo', age: 23},
{name: 'Foo', age: 17}
].map((item)=>{
return getName(item)
})
console.log(names)
// ["Bob", "Zoo", "Foo"]
來源:https://bit.ly/3qLvHz3
軟體開發趨勢(Why)
易擴充的思維與範例(What)
抽象化 abstraction
抽象化,將『具體的細節』,保留成『模糊或無定義』的樣子
單一職責原則 single responsibility principle SRP
可測試性 testability
JS 函數特性實作策略模式(How)
參考文章: 重新思考 jQuery
註: