[Pkg-javascript-commits] [backbone] 02/15: Adding empty initialize() function for all Backbone classes, to make calling super() a easier to get right.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:59:29 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.3.2
in repository backbone.

commit 99fbc0822434e284890bc729b19666c3a715dd61
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Tue Nov 16 17:21:53 2010 -0500

    Adding empty initialize() function for all Backbone classes, to make calling super() a easier to get right.
---
 backbone.js | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/backbone.js b/backbone.js
index 6de0d8b..e2e96ea 100644
--- a/backbone.js
+++ b/backbone.js
@@ -118,7 +118,7 @@
     this.set(attributes || {}, {silent : true});
     this._previousAttributes = _.clone(this.attributes);
     if (options && options.collection) this.collection = options.collection;
-    if (this.initialize) this.initialize(attributes, options);
+    this.initialize(attributes, options);
   };
 
   // Attach all inheritable methods to the Model prototype.
@@ -131,6 +131,10 @@
     // Has the item been changed since the last `"change"` event?
     _changed : false,
 
+    // Initialize is an empty function by default. Override it with your own
+    // initialization logic.
+    initialize : function(){},
+
     // Return a copy of the model's `attributes` object.
     toJSON : function() {
       return _.clone(this.attributes);
@@ -368,7 +372,7 @@
     this._boundOnModelEvent = _.bind(this._onModelEvent, this);
     this._reset();
     if (models) this.refresh(models, {silent: true});
-    if (this.initialize) this.initialize(models, options);
+    this.initialize(models, options);
   };
 
   // Define the Collection's inheritable methods.
@@ -378,6 +382,10 @@
     // This should be overridden in most cases.
     model : Backbone.Model,
 
+    // Initialize is an empty function by default. Override it with your own
+    // initialization logic.
+    initialize : function(){},
+
     // The JSON representation of a Collection is an array of the
     // models' attributes.
     toJSON : function() {
@@ -575,7 +583,7 @@
     options || (options = {});
     if (options.routes) this.routes = options.routes;
     this._bindRoutes();
-    if (this.initialize) this.initialize(options);
+    this.initialize(options);
   };
 
   // Cached regular expressions for matching named param parts and splatted
@@ -586,6 +594,10 @@
   // Set up all inheritable **Backbone.Controller** properties and methods.
   _.extend(Backbone.Controller.prototype, Backbone.Events, {
 
+    // Initialize is an empty function by default. Override it with your own
+    // initialization logic.
+    initialize : function(){},
+
     // Manually bind a single named route to a callback. For example:
     //
     //     this.route('search/:query/p:num', 'search', function(query, num) {
@@ -733,7 +745,7 @@
     this._configure(options || {});
     this._ensureElement();
     this.delegateEvents();
-    if (this.initialize) this.initialize(options);
+    this.initialize(options);
   };
 
   // jQuery lookup, scoped to DOM elements within the current view.
@@ -756,6 +768,10 @@
     $       : jQueryDelegate,
     jQuery  : jQueryDelegate,
 
+    // Initialize is an empty function by default. Override it with your own
+    // initialization logic.
+    initialize : function(){},
+
     // **render** is the core function that your view should override, in order
     // to populate its element (`this.el`), with the appropriate HTML. The
     // convention is for **render** to always return `this`.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list