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網頁應用程式設計
第三章
模型(Model)和資料
如果要將程式的狀態交由用戶端(client side)來管理,需要面臨的挑戰之一,就是如何
管理資料。傳統的做法,是由用戶端發出網頁請求、要求伺服器從資料庫中取出需要的
資料,將資料寫進網頁再回覆給用戶端。不過對於一個具備管理狀態能力(stateful)的
JavaScript 應用程式而言,資料管理將成為完全截然不同的一套流程。不需發出請求 /
得回應,也不需要存取伺服器端的變數。而是在取得遠端資料後暫存在用戶端。
雖然這樣的轉變,會造成一些困難,但這麼做還是會帶來一些好處。像是:存取用戶端
資料的速度會非常的快(因為資料是直接從用戶端的記憶體中取得)。這能讓應用程式
的操作介面擁有截然不同的風貌;讓使用者進行的每項操作,都能得到程式快速、即時
的回應,進而大幅改善使用者的操作體驗。
如果要將系統架構調整成在用戶端儲存資料,需要經過慎密的思考。因為調整的過程中
充滿了許多隱藏的陷阱和危機,許多開發經驗略為不足的程式設計師,往往會不小心落
入這些陷阱中—特別是當應用程式的規模越來越大時。本章將會說明進行這種架構轉換
的最佳做法,並會介紹一些較推薦的實務做法。
MVC 和命名空間(Namespacing
如果想要讓系統架構保持整齊、有條理,就一定要確保系統操作介面的呈現、狀態的
控制,以及資料的保存這三種不同的程式邏輯,都有明確的區隔開來。根據 MVC 樣式
的規範,管理資料的工作是交由模型(Model,也就是 MVC 中的「M」)負責。所有和
操控資料相關的程式邏輯和行為 ...
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