没有合适的资源?快使用搜索试试~ 我知道了~
Backbone fundamentals
3星 · 超过75%的资源 需积分: 10 13 下载量 43 浏览量
2013-11-20
16:53:23
上传
评论
收藏 2.8MB PDF 举报
温馨提示
试读
308页
Backbone.js is a lightweight JavaScript library that adds structure to your client-side code. It makes it easy to manage and decouple concerns in your application, leaving you with code that is more maintainable in the long term. This is an open-source book about the Backbone.js library for structuring JavaScript applications.
资源推荐
资源详情
资源评论
Contents
Prelude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Introduction 9
What Is MVC? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
What is Backbone.js? . . . . . . . . . . . . . . . . . . . . . . . . 10
When Do I Need A JavaScript MVC Framework? . . . . . . . . . 11
Why Consider Backbone.js? . . . . . . . . . . . . . . . . . . . . . 12
Setting Expectations . . . . . . . . . . . . . . . . . . . . . . . . . 12
Fundamentals 13
MVC & Backbone.js . . . . . . . . . . . . . . . . . . . . . . . . . 13
MVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Smalltalk-80 MVC . . . . . . . . . . . . . . . . . . . . . . . . . . 13
MVC Applied To The Web . . . . . . . . . . . . . . . . . . . . . 14
MVC In The Browser . . . . . . . . . . . . . . . . . . . . . . . . 16
Simple JavaScript MVC Implementation . . . . . . . . . . . . . . 17
Imlementation Specifics . . . . . . . . . . . . . . . . . . . . . . . 23
What does MVC give us? . . . . . . . . . . . . . . . . . . . . . . . . . 26
Delving deeper . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Fast facts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Backbone.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
The Internals 28
Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Underscore utility functions . . . . . . . . . . . . . . . . . . . . . 41
Chainable API . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1
Routers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Backbone’s Sync API . . . . . . . . . . . . . . . . . . . . . . . . 51
Conflict Management . . . . . . . . . . . . . . . . . . . . . . . . . 53
Inheritance & Mixins . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
DOM Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . 58
Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
RESTFul persistence . . . . . . . . . . . . . . . . . . . . . . . . . 59
Routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Namespacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Exercise 1: Todos - Your First Backbone.js App 65
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Application HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Todo model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Todo collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Application View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Individual Todo View . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
In action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
In action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Completing & deleting todos . . . . . . . . . . . . . . . . . . . . . . . 81
Todo routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Exercise 2: Book Library - Your first RESTful Backbone.js app 85
Part 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Setting up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Part 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Adding models . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Removing models . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
2
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Part 2.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Installing node modules . . . . . . . . . . . . . . . . . . . . . . . 107
Create directory structure . . . . . . . . . . . . . . . . . . . . . . 108
Create a simple web server . . . . . . . . . . . . . . . . . . . . . 108
Connect to database . . . . . . . . . . . . . . . . . . . . . . . . . 109
Part 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Connecting with a third party API . . . . . . . . . . . . . . . . . 128
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Backbone Boilerplate And Grunt-BBB 130
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Backbone Boilerplate . . . . . . . . . . . . . . . . . . . . . . . . . 130
Grunt-BBB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Creating a new project . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
index.html . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
config.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
main.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
app.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Creating Backbone Boilerplate Modules . . . . . . . . . . . . . . 138
router.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Related Tools & Projects . . . . . . . . . . . . . . . . . . . . . . . . . 144
Common Problems & Solutions 144
Backbone Extensions 160
Backbone.Marionette . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Boilerplate Rendering Code . . . . . . . . . . . . . . . . . . . . . 162
Reducing Boilerplate With Marionette.ItemView . . . . . . . . . 163
Memory Management . . . . . . . . . . . . . . . . . . . . . . . . 164
Region Management . . . . . . . . . . . . . . . . . . . . . . . . . 167
3
Marionette Todo app . . . . . . . . . . . . . . . . . . . . . . . . . 168
Is the Marionette implementation of the Todo app more main-
tainable? . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Marionette And Flexibility . . . . . . . . . . . . . . . . . . . . . 180
And So Much More . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Thorax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Embedding child views . . . . . . . . . . . . . . . . . . . . . . . . 183
View helpers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
collection helper . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Custom HTML data attributes . . . . . . . . . . . . . . . . . . . 186
Thorax Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Modular Development 189
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Organizing modules with RequireJS and AMD . . . . . . . . . . . . . 190
Maintainability problems with multiple script files . . . . . . . . 190
Need for better dependency management . . . . . . . . . . . . . 190
Asynchrous Module Definition (AMD) . . . . . . . . . . . . . . . 191
Writing AMD modules with RequireJS . . . . . . . . . . . . . . . 191
Getting Started with RequireJS . . . . . . . . . . . . . . . . . . . 193
Require.js and Backbone Examples . . . . . . . . . . . . . . . . . 196
Keeping Your Templates External Using RequireJS And The Text
Plugin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Optimizing Backbone apps for production with the RequireJS
Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Optimize and Build a Backbone.js JavaScript application with Re-
quireJS using Packages . . . . . . . . . . . . . . . . . . . . . . . . 201
Exercise: Building a modular Backbone app with AMD & RequireJS . 208
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Markup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Configuration options . . . . . . . . . . . . . . . . . . . . . . . . 210
Modularizing our models, views and collections . . . . . . . . . . 211
4
Route based module loading . . . . . . . . . . . . . . . . . . . . . . . . 217
JSON based module configuration . . . . . . . . . . . . . . . . . 217
Module loader Router . . . . . . . . . . . . . . . . . . . . . . . . 218
Using NodeJS to handle pushState . . . . . . . . . . . . . . . . . 220
Decoupling Backbone with the Mediator and Facade Patterns . . . . . 220
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Paginating Backbone.js Requests & Collections . . . . . . . . . . . . . 229
Paginator’s pieces . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Live Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Paginator.requestPager . . . . . . . . . . . . . . . . . . . . . . . . 230
Paginator.clientPager . . . . . . . . . . . . . . . . . . . . . . . . . 234
Plugins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Thorax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
view helper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Creating new View helpers . . . . . . . . . . . . . . . . . . . . . 239
Mobile Applications 240
Backbone & jQuery Mobile . . . . . . . . . . . . . . . . . . . . . . . . 240
Resolving the routing conflicts . . . . . . . . . . . . . . . . . . . 240
Exercise: A Backbone, Require.js/AMD app with jQuery Mobile 241
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
jQuery Mobile: Going beyond mobile application development . 243
Unit Testing 244
Jasmine 244
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Suites, Specs & Spies . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
beforeEach and afterEach() . . . . . . . . . . . . . . . . . . . . . . . . 249
Shared scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Getting setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
5
剩余307页未读,继续阅读
资源评论
- j2huanxiang2014-04-16不错的资料,值得一看!
lxh0959
- 粉丝: 4
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功