Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
初探 functional programming
Search
CypressKuo
February 03, 2017
Technology
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
初探 functional programming
CypressKuo
February 03, 2017
Transcript
27 slides
初探 functional programming in JavaScript CypressKuo @前端組例會 2017/02/03 1
定義 一種程式設計的方法/概念 2
3
4
特色 ✣ Expression, no Statement ✣ First-class ✣ High order
function ✣ No side effect ✣ Referential transparency ✣ Pure Function 5
Expression, no Statement Expression Statement 6
First-class 函數與其他數據類型一樣,處於平等地位。 可以被賦值到其他變數, 也可以作為參數傳入到不同的函數中, 或者作為函數的回傳值。 7
8
9
10
High order function 滿足以下兩項其中之一的函數 ✣ 可以將函式當成參數傳入的函式 ✣ 可以將函式當成回傳值的函式 11
12
✣ .map() ✣ .filter() ✣ .reduce() ✣ .forEach() ✣ .some()
✣ .every() 常見的 High order function 13
No side effect 沒有與外部互動,產生與運算無關的其他結果。 ✣ 發送 http request ✣ 印出
console ✣ 取得使用者的 input 14
Referential transparency 不管外部環境如何,只要參數相同,函式執行的返回結果必定相同。 15
Pure Function 結合 no side effect 與 Referential transparency 一個
function 給予相同的參數, 永遠會回傳相同的返回值,並且沒有任何顯著的副作用 16
17
18
Function Composition ✣ Curry ✣ Compose 19
curry 將一個有 N 個參數的函數轉換成 N 個只有一個參數的函數 20
21
22
compose 把兩個以上的一個參數函數合併起來串聯多個組合成新的函數 23
24
25
優勢 ✣ 可讀性高 ✣ 可維護性高 ✣ 簡潔,開發快速 26
參考資料 http://blog.miniasp.com/post/2016/12/10/Functional-Programming-in-JavaScript.aspx?s=2 http://www.ruanyifeng.com/blog/2012/04/functional_programming.html http://www.slideshare.net/rockncoder/functional-programming-in-javascript-68835257 http://www.slideshare.net/ihower/fp-osdc2012v2 https://github.com/MostlyAdequate/mostly-adequate-guide http://ithelp.ithome.com.tw/articles/10186465 27
More Decks by CypressKuo
See All by CypressKuo
Deep-copying.pdf
cypresskuo
0
45
CSS_for_Web_Vitals.pdf
cypresskuo
0
52
談談_Code_review.pdf
cypresskuo
0
57
REST_vs_GraphQL_今夜はご注文はどっち.pdf
cypresskuo
0
31
CSS_重構.pdf
cypresskuo
0
37
跟上_JS_的腳步-ES2020.pdf
cypresskuo
0
43
Core_Web_Vitals.pdf
cypresskuo
0
65
這個時代人人都知道的敏捷開發.pdf
cypresskuo
0
93
Webassembly.pdf
cypresskuo
0
24
Other Decks in Technology
See All in Technology
現場に渡し、構造で守る AI エージェントを活用したセルフサーブのデータ基盤の運用
legalontechnologies
PRO
0
180
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
5
18k
本の挿絵に困ったから挿絵メーカーを自作した
yoshimura_datam
1
140
対話 AI プラットフォーム「アイブリー」で実践する自然言語処理と事業開発
ivry_presentationmaterials
0
230
コーディングできない僕にBobが舞い降りた
shumpei3
0
230
Is the Website Dying?
miriamschwab
0
270
信頼性を犠牲にせず、PR マージからデプロイまで人の介入を完全にゼロにするまでの道のり
knwoop
4
2.3k
競馬予想をAIでやってみた話
yoshimura_datam
0
170
生成AIによる情報システムへのインパクト (2026年11月版)
taka_aki
0
130
AIエージェントのアーキテクチャ設計
nsatoh
0
600
LLMごとの文章力を測ってみた話
yoshimura_datam
0
130
Amazon EFS のマルウェアスキャンをClamAV で自前実装したら苦労した話
mtmtfactory01
0
130
Featured
See All Featured
Darren the Foodie - Storyboard
khoart
PRO
5
4.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
640
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
My Coaching Mixtape
mlcsv
0
400
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
630
How to Ace a Technical Interview
jacobian
280
24k
Prompt Engineering for Job Search
mfonobong
0
620
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
530
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
121
130k