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網頁應用程式設計
Spine 函式庫
|
179
Spine 的事件機制,最常被用來同步模型和檢視器,好讓雙方所持有的資料能維持一
致。本章稍後的「實際開發應用程式:聯絡人管理員」一節,將會更詳盡的解說相關的
概念。
模型
如果你有偷瞄一下 Spine 的原始碼(
https://github.com/maccman/spine/blob/master/spine.
js
),就會發現裡面大多數的程式碼,都是在處理模型。的確,模型可說是每套 MVC
用程式最核心的關鍵,它主要是負責儲存、處理應用程式的資料。Spine 為了能簡化處
理模型的工作,特別提供了一套完整的 ORM 模組。
如果要建立新的模型,用的不是
create()
函式(這組函式已經有其他用途),而是
Spine.Model.setup(name, attrs)
,傳入兩組參數:模型名稱(name),以及一組存放
屬性名稱的陣列(attrs):
// 建立工作項目的模型「Task
var Task = Spine.Model.setup("Task", ["name", "done"]);
建立好模型,就可以用
include()
extend()
函式,來新增實體屬性和類別屬性:
Task.extend({
// 回傳所有已完成的工作項目
done: function(){ /* ... */ }
});
Task.include({
// 預設的工作項目名稱
name: "Empty...",
done: false,
toggle: function(){ ...
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