|
394 | 394 | var Model = Backbone.Model = function(attributes, options) {
|
395 | 395 | var attrs = attributes || {};
|
396 | 396 | options || (options = {});
|
| 397 | + _.extend(this, _.result(this, 'localProps')); |
397 | 398 | this.cid = _.uniqueId(this.cidPrefix);
|
398 | 399 | this.attributes = {};
|
399 | 400 | if (options.collection) this.collection = options.collection;
|
|
421 | 422 | // You may want to override this if you're experiencing name clashes with model ids.
|
422 | 423 | cidPrefix: 'c',
|
423 | 424 |
|
| 425 | + // localProps is an empty function by default. You can override it with a function |
| 426 | + // or object. The results of evaluating localProps will be mixed in to each instance |
| 427 | + // of the Model |
| 428 | + localProps: function(){}, |
| 429 | + |
424 | 430 | // Initialize is an empty function by default. Override it with your own
|
425 | 431 | // initialization logic.
|
426 | 432 | initialize: function(){},
|
|
753 | 759 | // its models in sort order, as they're added and removed.
|
754 | 760 | var Collection = Backbone.Collection = function(models, options) {
|
755 | 761 | options || (options = {});
|
| 762 | + _.extend(this, _.result(this, 'localProps')); |
756 | 763 | if (options.model) this.model = options.model;
|
757 | 764 | if (options.comparator !== void 0) this.comparator = options.comparator;
|
758 | 765 | this._reset();
|
|
781 | 788 | // This should be overridden in most cases.
|
782 | 789 | model: Model,
|
783 | 790 |
|
| 791 | + |
| 792 | + // localProps is an empty function by default. You can override it with a function |
| 793 | + // or object. The results of evaluating localProps will be mixed in to each instance |
| 794 | + // of the Collection |
| 795 | + localProps: function(){}, |
| 796 | + |
784 | 797 | // Initialize is an empty function by default. Override it with your own
|
785 | 798 | // initialization logic.
|
786 | 799 | initialize: function(){},
|
|
1192 | 1205 | // Creating a Backbone.View creates its initial element outside of the DOM,
|
1193 | 1206 | // if an existing element is not provided...
|
1194 | 1207 | var View = Backbone.View = function(options) {
|
| 1208 | + |
1195 | 1209 | this.cid = _.uniqueId('view');
|
| 1210 | + _.extend(this, _.result(this, 'localProps')); |
1196 | 1211 | _.extend(this, _.pick(options, viewOptions));
|
1197 | 1212 | this._ensureElement();
|
1198 | 1213 | this.initialize.apply(this, arguments);
|
|
1216 | 1231 | return this.$el.find(selector);
|
1217 | 1232 | },
|
1218 | 1233 |
|
| 1234 | + // localProps is an empty function by default. You can override it with a function |
| 1235 | + // or object. The results of evaluating localProps will be mixed in to each instance |
| 1236 | + // of the View |
| 1237 | + localProps: function(){}, |
| 1238 | + |
1219 | 1239 | // Initialize is an empty function by default. Override it with your own
|
1220 | 1240 | // initialization logic.
|
1221 | 1241 | initialize: function(){},
|
|
1441 | 1461 | // matched. Creating a new one sets its `routes` hash, if not set statically.
|
1442 | 1462 | var Router = Backbone.Router = function(options) {
|
1443 | 1463 | options || (options = {});
|
| 1464 | + _.extend(this, _.result(this, 'localProps')); |
1444 | 1465 | if (options.routes) this.routes = options.routes;
|
1445 | 1466 | this._bindRoutes();
|
1446 | 1467 | this.initialize.apply(this, arguments);
|
|
1456 | 1477 | // Set up all inheritable **Backbone.Router** properties and methods.
|
1457 | 1478 | _.extend(Router.prototype, Events, {
|
1458 | 1479 |
|
| 1480 | + // localProps is an empty function by default. You can override it with a function |
| 1481 | + // or object. The results of evaluating localProps will be mixed in to each instance |
| 1482 | + // of the Router |
| 1483 | + localProps: function(){}, |
| 1484 | + |
1459 | 1485 | // Initialize is an empty function by default. Override it with your own
|
1460 | 1486 | // initialization logic.
|
1461 | 1487 | initialize: function(){},
|
|
0 commit comments