Skip to Content
JAVASCRIPT網頁應用程式設計
book

JAVASCRIPT網頁應用程式設計

by Alex MacCaw
January 2013
Intermediate to advanced
332 pages
5h 23m
Chinese
GoTop Information, Inc.
Content preview from JAVASCRIPT網頁應用程式設計
70
|
第四章
search: function(){
alert("Searching: " + this.searchInput.val());
return false;
},
});
new SearchView({el: "#users"});
});
狀態機(State Machines
狀態機—較專業的術語應該是
有限狀態機
Finite State Machines
簡稱
FSMs
—是一
種開發 UI 的絕佳做法。只要善用狀態機,就能讓管理多組控制器、視情況需要顯示或
隱藏檢視器…等工作變得很容易。那麼,究竟狀態機是什麼意思?基本上,狀態機是由
兩項元素組成:狀態(state)和轉換函式(transition)。啟用的狀態永遠只會有一個,
停用的狀態則會有很多個。當我們將某個狀態設為停用,把另一個狀態設為啟用時,就
會觸發介於兩種狀態之間的轉換函式。
那我們該如何在實務上運用這樣的概念?假如你的應用程式裡有兩個需要獨立呈現的檢
視器(例如:顯示資料,和編輯資料的檢視器),而且這兩個檢視器永遠無法同時並存
時(當其中一個呈現顯示狀態,另一個就一定要被隱藏),就非常適合使用狀態機,因
為狀態機能確保同一時間內一定只會有一個啟用的狀態。而且如果日後想要新增其他的
檢視器(像是用來進行設定的檢視器),透過狀態機來處理也會非常的容易。
讓我們再舉個實際的範例,好讓你對狀態機的實作方式有更清楚的概念。雖然接下來這
段範例程式非常簡單,而且沒有用到不同的轉換類型,但已足以滿足我們的需求。首先
建立一組 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

Ethan Brown, 武舎 広幸, 武舎 るみ
PHP编程:第4版

PHP编程:第4版

Kevin Tatroe, Peter MacIntyre
Strange Code

Strange Code

Ronald T. Kneusel
Perfecting Your Thinking Skills

Perfecting Your Thinking Skills

MIT Sloan Management Review

Publisher Resources

ISBN: 9789862766811