Permalink
Browse files

added Marionette.extend as alias to Backbone's extend method

  • Loading branch information...
1 parent a759a35 commit 3316ac09a5e96a0fe69ee8656d9aa5a13fbf1c80 @derickbailey derickbailey committed Oct 7, 2012
View
@@ -45,6 +45,7 @@
* Added `Marionette.addEventBinder` method to add all of the Backbone.Wreqr.EventBinder methods to a specified target object
* Misc
+ * Added `Marionette.extend` as alias to Backbone's `extend` method for more consistent use
* jQuery ($) support now works from global `$` or `window.jQuery`
* Updated to Underscore.js v1.4.1
* Updated to jQuery v1.8.2
@@ -40,3 +40,30 @@ of it being attached to the view. For example, the internal structure
used to store the events can change without worry about it interfering
with Marionette's views.
+## Marionette.extend
+
+Backbone's `extend` function is a useful utility to have, and is used in
+various places in Marionette. To make the use of this method more consistent,
+Backbone's `extend` has been aliased to `Marionette.extend`. This allows
+you to get the extend functionality for your object without having to
+decide if you want to use Backbone.View or Backbone.Model or another
+Backbone object to grab the method from.
+
+```js
+var Foo = function(){};
+
+// use Marionette.extend to make Foo extendable, just like other
+// Backbone and Marionette objects
+Foo.extend = Marionette.extend;
+
+// Now Foo can be extended to create a new type, with methods
+var Bar = Foo.extend({
+
+ someMethod: function(){ ... }
+
+ // ...
+});
+
+// Create an instance of Bar
+var b = new Bar();
+```
View
@@ -50,6 +50,7 @@ module.exports = function(grunt) {
'public/javascripts/backbone.wreqr.js',
'src/marionette.js',
'spec/javascripts/support/marionette.support.js',
+ 'src/marionette.helpers.js',
'src/marionette.triggermethod.js',
'src/marionette.eventbinder.js',
'src/marionette.view.js',
@@ -64,8 +65,7 @@ module.exports = function(grunt) {
'src/marionette.templatecache.js',
'src/marionette.renderer.js',
'src/marionette.callbacks.js',
- 'src/marionette.eventaggregator.js',
- 'src/marionette.helpers.js'
+ 'src/marionette.eventaggregator.js'
],
helpers : 'spec/javascripts/helpers/*.js',
specs : 'spec/javascripts/**/*.spec.js'
@@ -21,6 +21,15 @@
Backbone.Marionette = Marionette = (function(Backbone, _, $){
var Marionette = {};
+ // Helpers
+ // -------
+
+ // For slicing `arguments` in functions
+ var slice = Array.prototype.slice;
+
+ // Borrow the Backbone `extend` method so we can use it as needed
+ Marionette.extend = Backbone.Model.extend;
+
// Trigger an event and a corresponding method name. Examples:
//
// `this.triggerMethod("foo")` will trigger the "foo" event and
@@ -849,7 +858,7 @@
});
// Copy the `extend` function used by Backbone's classes
- Marionette.Region.extend = Backbone.View.extend;
+ Marionette.Region.extend = Marionette.extend;
// Layout
// ------
@@ -1037,7 +1046,7 @@
});
// Copy the `extend` function used by Backbone's classes
- Marionette.Application.extend = Backbone.View.extend;
+ Marionette.Application.extend = Marionette.extend;
// AppRouter
// ---------
@@ -1492,12 +1501,6 @@
// https://github.com/marionettejs/backbone.wreqr
Marionette.EventAggregator = Backbone.Wreqr.EventAggregator;
- // Helpers
- // -------
-
- // For slicing `arguments` in functions
- var slice = Array.prototype.slice;
-
return Marionette;
})(Backbone, _, $ || window.jQuery || window.Zepto || window.ender);

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -5,6 +5,15 @@
Backbone.Marionette = Marionette = (function(Backbone, _, $){
var Marionette = {};
+// Helpers
+// -------
+
+// For slicing `arguments` in functions
+var slice = Array.prototype.slice;
+
+// Borrow the Backbone `extend` method so we can use it as needed
+Marionette.extend = Backbone.Model.extend;
+
// Trigger an event and a corresponding method name. Examples:
//
// `this.triggerMethod("foo")` will trigger the "foo" event and
@@ -833,7 +842,7 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
});
// Copy the `extend` function used by Backbone's classes
-Marionette.Region.extend = Backbone.View.extend;
+Marionette.Region.extend = Marionette.extend;
// Layout
// ------
@@ -1021,7 +1030,7 @@ _.extend(Marionette.Application.prototype, Backbone.Events, {
});
// Copy the `extend` function used by Backbone's classes
-Marionette.Application.extend = Backbone.View.extend;
+Marionette.Application.extend = Marionette.extend;
// AppRouter
// ---------
@@ -1476,12 +1485,6 @@ _.extend(Marionette.Callbacks.prototype, {
// https://github.com/marionettejs/backbone.wreqr
Marionette.EventAggregator = Backbone.Wreqr.EventAggregator;
-// Helpers
-// -------
-
-// For slicing `arguments` in functions
-var slice = Array.prototype.slice;
-
return Marionette;
})(Backbone, _, $ || window.jQuery || window.Zepto || window.ender);

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -78,4 +78,4 @@ _.extend(Marionette.Application.prototype, Backbone.Events, {
});
// Copy the `extend` function used by Backbone's classes
-Marionette.Application.extend = Backbone.View.extend;
+Marionette.Application.extend = Marionette.extend;
@@ -3,3 +3,6 @@
// For slicing `arguments` in functions
var slice = Array.prototype.slice;
+
+// Borrow the Backbone `extend` method so we can use it as needed
+Marionette.extend = Backbone.Model.extend;
View
@@ -1,6 +1,7 @@
Backbone.Marionette = Marionette = (function(Backbone, _, $){
var Marionette = {};
+//= marionette.helpers.js
//= marionette.triggerMethod.js
//= marionette.eventbinder.js
//= marionette.view.js
@@ -16,7 +17,6 @@ Backbone.Marionette = Marionette = (function(Backbone, _, $){
//= marionette.renderer.js
//= marionette.callbacks.js
//= marionette.eventaggregator.js
-//= marionette.helpers.js
return Marionette;
})(Backbone, _, $ || window.jQuery || window.Zepto || window.ender);
View
@@ -170,4 +170,4 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
});
// Copy the `extend` function used by Backbone's classes
-Marionette.Region.extend = Backbone.View.extend;
+Marionette.Region.extend = Marionette.extend;

0 comments on commit 3316ac0

Please sign in to comment.