Skip to content

Instantly share code, notes, and snippets.

@dmitry
Forked from wesen/backbone-mixin.js
Created October 1, 2011 21:49
Show Gist options
  • Save dmitry/1256695 to your computer and use it in GitHub Desktop.
Save dmitry/1256695 to your computer and use it in GitHub Desktop.

Revisions

  1. @wesen wesen revised this gist Aug 22, 2011. No changes.
  2. @wesen wesen renamed this gist Aug 21, 2011. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions backbone-mixin → backbone-mixin.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    ## Merging mixin views in backbone.js ##

    really just more a test for tumblr gistr

    ```js
    /**
    * ## Merging mixin views in backbone.js ##
    *
    * really just more a test for tumblr gistr
    */

    /**
    * Merge the mixin (a Backbone.View) into another Backbone.View. Automatically merge events, defaults, and call the parent initializer.
    @@ -14,5 +14,4 @@ function mergeMixin(view, mixin) {
    var oldInitialize = view.prototype.initialize;
    view.prototype.initialize = function () { mixin.initialize.apply(this); oldInitialize.apply(this); };
    }
    }
    ```
    }
  3. @wesen wesen revised this gist Aug 21, 2011. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion backbone-mixin
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    /* really just more a test for tumblr gistr */
    ## Merging mixin views in backbone.js ##

    really just more a test for tumblr gistr

    ```js

    /**
    * Merge the mixin (a Backbone.View) into another Backbone.View. Automatically merge events, defaults, and call the parent initializer.
    @@ -11,3 +15,4 @@ function mergeMixin(view, mixin) {
    view.prototype.initialize = function () { mixin.initialize.apply(this); oldInitialize.apply(this); };
    }
    }
    ```
  4. @wesen wesen created this gist Aug 21, 2011.
    13 changes: 13 additions & 0 deletions backbone-mixin
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    /* really just more a test for tumblr gistr */

    /**
    * Merge the mixin (a Backbone.View) into another Backbone.View. Automatically merge events, defaults, and call the parent initializer.
    **/
    function mergeMixin(view, mixin) {
    _.defaults(view.prototype, mixin);
    _.defaults(view.prototype.events, mixin.events);
    if (mixin.initialize !== undefined) {
    var oldInitialize = view.prototype.initialize;
    view.prototype.initialize = function () { mixin.initialize.apply(this); oldInitialize.apply(this); };
    }
    }