232
232
< p >
233
233
< i >
234
234
Backbone is an open-source component of
235
- < a href ="http://documentcloud.org/ "> DocumentCloud</ a > .< br />
236
- Special thanks to < a href ="http://github.com/broofa "> Robert Kieffer</ a >
237
- for inspiring the ideas behind this library.
235
+ < a href ="http://documentcloud.org/ "> DocumentCloud</ a > .
238
236
</ i >
239
237
</ p >
240
238
@@ -246,7 +244,7 @@ <h2 id="downloads">
246
244
< table >
247
245
< tr >
248
246
< td > < a href ="backbone.js "> Development Version (0.1.0)</ a > </ td >
249
- < td > < i > 22kb , Uncompressed with Comments</ i > </ td >
247
+ < td > < i > 21kb , Uncompressed with Comments</ i > </ td >
250
248
</ tr >
251
249
< tr >
252
250
< td > < a href ="backbone-min.js "> Production Version (0.1.0)</ a > </ td >
@@ -267,8 +265,8 @@ <h2 id="downloads">
267
265
< h2 id ="Introduction "> Introduction</ h2 >
268
266
269
267
< p >
270
- When working on a heavy-duty JavaScript application, one of the first things
271
- you learn is to stop tying your data to the DOM. It's all
268
+ When working on a web application that involved a lot of JavaScript, one
269
+ of the first things you learn is to stop tying your data to the DOM. It's all
272
270
too easy to create JavaScript applications that end up as tangled piles of
273
271
jQuery selectors and callbacks, all trying frantically to keep data in
274
272
sync between the HTML UI, your JavaScript logic, and the database on your
@@ -281,7 +279,7 @@ <h2 id="Introduction">Introduction</h2>
281
279
< a href ="#Model "> Models</ a > , which can be created, validated, destroyed,
282
280
and saved to the server. Whenever a UI action causes an attribute of
283
281
a model to change, the model triggers a < i > "change"</ i > event; all
284
- the < a href ="#View "> Views</ a > that reference the model's data receive the
282
+ the < a href ="#View "> Views</ a > that display the model's data receive the
285
283
event, causing them to re-render. You don't have to write the glue
286
284
code that looks into the DOM to find an element with a specific < i > id</ i > ,
287
285
and update the HTML manually
@@ -353,8 +351,8 @@ <h2 id="Events">Backbone.Events</h2>
353
351
</ p >
354
352
355
353
< pre >
356
- object .bind("all", function(eventName) {
357
- proxy .trigger(eventName);
354
+ proxy .bind("all", function(eventName) {
355
+ object .trigger(eventName);
358
356
});
359
357
</ pre >
360
358
@@ -379,7 +377,7 @@ <h2 id="Events">Backbone.Events</h2>
379
377
< b class ="header "> trigger</ b > < code > object.trigger(event, [*args])</ code >
380
378
< br />
381
379
Trigger all callbacks for the given < b > event</ b > . All subsequent arguments to
382
- < b > trigger</ b > will be passed along.
380
+ < b > trigger</ b > will be passed along to the event callbacks .
383
381
</ p >
384
382
385
383
< h2 id ="Model "> Backbone.Model</ h2 >
@@ -394,8 +392,8 @@ <h2 id="Model">Backbone.Model</h2>
394
392
395
393
< p >
396
394
The following is a contrived example, but it demonstrates defining a model
397
- with a custom method, setting an attribute, and firing an event when a
398
- specific property of the model changes .
395
+ with a custom method, setting an attribute, and firing an event keyed
396
+ to changes in that specific attribute .
399
397
After running this code once, < tt > sidebar</ tt > will be
400
398
available in your browser's console, so you can play around with it.
401
399
</ p >
@@ -420,11 +418,11 @@ <h2 id="Model">Backbone.Model</h2>
420
418
</ pre >
421
419
422
420
< p id ="Model-extend ">
423
- < b class ="header "> extend</ b > < code > Backbone.Model.extend(properties, [staticProperties ])</ code >
421
+ < b class ="header "> extend</ b > < code > Backbone.Model.extend(properties, [classProperties ])</ code >
424
422
< br />
425
423
To create a < b > Model</ b > class of your own, you extend < b > Backbone.Model</ b >
426
- and provide instance < b > properties</ b > , as well as optional properties to be attached
427
- directly to the constructor function.
424
+ and provide instance < b > properties</ b > , as well as optional
425
+ < b > classProperties </ b > to be attached directly to the constructor function.
428
426
</ p >
429
427
430
428
< p >
@@ -456,18 +454,17 @@ <h2 id="Model">Backbone.Model</h2>
456
454
< br />
457
455
Set a hash of attributes (one or many) on the model. If any of the attributes
458
456
change the models state, a < tt > "change"</ tt > event will be fired, unless
459
- < tt > silent</ tt > is passed as an option.
457
+ < tt > { silent: true} </ tt > is passed as an option.
460
458
</ p >
461
459
462
460
< p >
463
- If the model has a < tt > validate</ tt > method, it will be validated before
464
- the attributes are set, and no changes will occur if the validation fails.
461
+ If the model has a < a href ="#Model-validate "> validate</ a > method,
462
+ it will be validated before the attributes are set, and no changes will
463
+ occur if the validation fails.
465
464
</ p >
466
465
467
466
< pre >
468
467
note.set({title: "October 12", content: "Lorem Ipsum Dolor Sit Amet..."});
469
-
470
- note.set({title: "October 31"}, {silent: true});
471
468
</ pre >
472
469
473
470
< p id ="Model-unset ">
@@ -501,15 +498,15 @@ <h2 id="Model">Backbone.Model</h2>
501
498
< b class ="header "> attributes</ b > < code > model.attributes</ code >
502
499
< br />
503
500
The < b > attributes</ b > property is the internal hash containing the model's
504
- state. Please use < tt > set</ tt > to update the attributes instead of modifying
501
+ state. Please use < a href =" #Model-set " > set</ a > to update the attributes instead of modifying
505
502
them directly. If you'd like to retrieve and munge a copy of the model's
506
- attributes, use < tt > toJSON</ tt > instead.
503
+ attributes, use < a href =" #Model-toJSON " > toJSON</ a > instead.
507
504
</ p >
508
505
509
506
< p id ="Model-toJSON ">
510
507
< b class ="header "> toJSON</ b > < code > model.toJSON</ code >
511
508
< br />
512
- Return a copy of the model's < b > attributes</ b > for JSON stringification.
509
+ Return a copy of the model's < a href =" #Model-attributes " > attributes</ a > for JSON stringification.
513
510
This can be used for persistence, serialization, or for augmentation before
514
511
being handed off to a view.
515
512
</ p >
@@ -529,16 +526,18 @@ <h2 id="Model">Backbone.Model</h2>
529
526
< b class ="header "> save</ b > < code > model.save(attributes, [options])</ code >
530
527
< br />
531
528
Save a model to your database (or alternative persistence layer),
532
- by delegating to < tt > Backbone.sync</ tt > . If the model has a < tt > validate</ tt >
529
+ by delegating to < a href =" #Sync " > Backbone.sync</ a > . If the model has a < a href =" #Model-validate " > validate</ a >
533
530
method, and validation fails, the model will not be saved. If the model
534
- < tt > isNew()</ tt > , the save will be an HTTP < tt > POST</ tt > , if the model already
535
- exists on the server, the save will be a < tt > PUT</ tt > . Accepts
536
- < tt > success</ tt > and < tt > error</ tt > callbacks in the options hash.
531
+ < a href ="#Model-isNew "> isNew</ a > , the save will be a < tt > "create"</ tt >
532
+ (HTTP < tt > POST</ tt > ), if the model already
533
+ exists on the server, the save will be an < tt > "update"</ tt > (HTTP < tt > PUT</ tt > ). Accepts
534
+ < tt > success</ tt > and < tt > error</ tt > callbacks in the options hash, which
535
+ are passed < tt > (model, response)</ tt > as arguments.
537
536
</ p >
538
537
539
538
< p >
540
539
In the following example, notice how because the model has never been
541
- saved previously, < tt > Backbone.sync</ tt > receives a < tt > "create"</ tt > request.
540
+ saved previously, our overridden version of < tt > Backbone.sync</ tt > receives a < tt > "create"</ tt > request.
542
541
</ p >
543
542
544
543
< pre class ="runnable ">
@@ -558,7 +557,7 @@ <h2 id="Model">Backbone.Model</h2>
558
557
< b class ="header "> destroy</ b > < code > model.destroy([options])</ code >
559
558
< br />
560
559
Destroys the model on the server by delegating an HTTP < tt > DELETE</ tt >
561
- request to < tt > Backbone.sync</ tt > . Accepts
560
+ request to < a href =" #Sync " > Backbone.sync</ a > . Accepts
562
561
< tt > success</ tt > and < tt > error</ tt > callbacks in the options hash.
563
562
</ p >
564
563
@@ -616,14 +615,14 @@ <h2 id="Model">Backbone.Model</h2>
616
615
617
616
< p >
618
617
A model with an id of < tt > 101</ tt > , stored in a
619
- < b > Backbone.Collection</ b > with a < tt > url</ tt > of < tt > "/notes"</ tt > ,
618
+ < a href =" #Collection " > Backbone.Collection</ a > with a < tt > url</ tt > of < tt > "/notes"</ tt > ,
620
619
would have this URL: < tt > "/notes/101"</ tt >
621
620
</ p >
622
621
623
622
< p id ="Model-clone ">
624
623
< b class ="header "> clone</ b > < code > model.clone()</ code >
625
624
< br />
626
- Create a new instance of a model with identical attributes.
625
+ Returns a new instance of the model with identical attributes.
627
626
</ p >
628
627
629
628
< p id ="Model-isNew ">
@@ -636,9 +635,10 @@ <h2 id="Model">Backbone.Model</h2>
636
635
< p id ="Model-change ">
637
636
< b class ="header "> change</ b > < code > model.change()</ code >
638
637
< br />
639
- If you've been passing < tt > {silent: true}</ tt > to < tt > set</ tt > in order to
640
- aggregate rapid changes to a model, you'll want to fire the < tt > "change"</ tt >
641
- event when you're finished. Call < tt > model.change()</ tt > to trigger it.
638
+ Manually trigger the < tt > "change"</ tt > event.
639
+ If you've been passing < tt > {silent: true}</ tt > to the < a href ="#Model-set "> set</ a > function in order to
640
+ aggregate rapid changes to a model, you'll want to call < tt > model.change()</ tt >
641
+ when you're all finished.
642
642
</ p >
643
643
644
644
< p id ="Model-hasChanged ">
@@ -712,7 +712,7 @@ <h2 id="Collection">Backbone.Collection</h2>
712
712
</ p >
713
713
714
714
< p id ="Collection-extend ">
715
- < b class ="header "> extend</ b > < code > Backbone.Collection.extend(properties, [staticProperties ])</ code >
715
+ < b class ="header "> extend</ b > < code > Backbone.Collection.extend(properties, [classProperties ])</ code >
716
716
< br />
717
717
To create a < b > Collection</ b > class of your own, extend < b > Backbone.Collection</ b > ,
718
718
providing instance < b > properties</ b > , as well as optional properties to be attached
0 commit comments