/vendor-jsdoc/backbonejs/backbone-collection.js

https://github.com/cancerberoSgx/short-jsdoc · JavaScript · 92 lines · 0 code · 10 blank · 82 comment · 0 complexity · 67622e09ed5e6622b081ecc9bb292e06 MD5 · raw file

  1. /*
  2. @module Backbone
  3. @class Backbone.Collection
  4. Collections are ordered sets of models. You can bind "change" events to be notified when any model in the collection has been modified, listen for "add" and "remove" events, fetch the collection from the server, and use a full suite of Underscore.js methods.
  5. Any event that is triggered on a model in a collection will also be triggered on the collection directly, for convenience. This allows you to listen for changes to specific attributes in any model in a collection, for example: documents.on("change:selected", ...)
  6. @method extend
  7. To create a Collection class of your own, extend Backbone.Collection, providing instance properties, as well as optional classProperties to be attached directly to the collection's constructor function.
  8. @param {Object} properties
  9. @param {Object} classProperties Optional
  10. */
  11. /* @method model
  12. Override this property to specify the model class that the collection contains. If defined, you can pass raw attributes objects (and arrays) to add, create, and reset, and the attributes will be converted into a model of the proper type.
  13. var Library = Backbone.Collection.extend({
  14. model: Book
  15. });
  16. A collection can also contain polymorphic models by overriding this property with a constructor that returns a model.
  17. var Library = Backbone.Collection.extend({
  18. model: function(attrs, options) {
  19. if (condition) {
  20. return new PublicDocument(attrs, options);
  21. } else {
  22. return new PrivateDocument(attrs, options);
  23. }
  24. }
  25. });
  26. @param {Object}attrs
  27. @param {Object} options
  28. */
  29. /*
  30. @constructor
  31. When creating a Collection, you may choose to pass in the initial array of models. The collection's comparator may be included as an option. Passing false as the comparator option will prevent sorting. If you define an initialize function, it will be invoked when the collection is created. There are a couple of options that, if provided, are attached to the collection directly: model and comparator.
  32. var tabs = new TabSet([tab1, tab2, tab3]);
  33. var spaces = new Backbone.Collection([], {
  34. model: Space
  35. });
  36. @param {Array} models optional
  37. @param {Object} options optional
  38. */
  39. /*
  40. @property {Array} models
  41. Raw access to the JavaScript array of models inside of the collection. Usually you'll want to use get, at, or the Underscore methods to access model objects, but occasionally a direct reference to the array is desired.
  42. */
  43. /*@method toJSON
  44. Return an array containing the attributes hash of each model (via toJSON) in the collection. This can be used to serialize and persist the collection as a whole. The name of this method is a bit confusing, because it conforms to JavaScript's JSON API.
  45. var collection = new Backbone.Collection([
  46. {name: "Tim", age: 5},
  47. {name: "Ida", age: 26},
  48. {name: "Rob", age: 55}
  49. ]);
  50. alert(JSON.stringify(collection));
  51. @returns {Array}
  52. */
  53. /*
  54. @method sync
  55. synccollection.sync(method, collection, [options])
  56. Uses Backbone.sync to persist the state of a collection to the server. Can be overridden for custom behavior.
  57. @param {String} method
  58. @param {Backbone.Collection} collection
  59. @param {Object} options optional
  60. */