Permalink
Browse files

Merge pull request #211 from jvitela/gh-pages

Using Backbone-super plugin for calling the object parent methods
  • Loading branch information...
2 parents d83a7b7 + 751f432 commit 90aa66dab8de44a5fab26ec333beac42c96ddb66 @addyosmani committed Nov 9, 2012
Showing with 30 additions and 0 deletions.
  1. +30 −0 index.md
View
@@ -1801,6 +1801,36 @@ When used appropriately, Backbone's `extend` method can save a great deal of tim
(Thanks to [Alex Young](http://dailyjs.com), [Derick Bailey](http://stackoverflow.com/users/93448/derick-bailey) and [JohnnyO](http://stackoverflow.com/users/188740/johnnyo) for the heads up about these tips).
+#### Backbone-Super
+
+[Backbone-Super](https://github.com/lukasolson/Backbone-Super) by Lukas Olson adds a *_super* method to *Backbone.Model* using [John Resig’s Inheritance script](http://ejohn.org/blog/simple-javascript-inheritance/).
+Rather than using Backbone.Model.prototype.set.call as per the Backbone.js documentation, _super can be called instead:
+
+```javascript
+// This is how we normally do it
+var OldFashionedNote = Backbone.Model.extend({
+ set: function( attributes, options ) {
+ // Call parent's method
+ Backbone.Model.prototype.set.call(this, attributes, options);
+ // some custom code here
+ // ...
+ }
+});
+```
+
+After including this plugin, you can do the same thing with the following syntax:
+
+```javascript
+// This is how we can do it after using the Backbone-super plugin
+var Note = Backbone.Model.extend({
+ set: function(attributes, options) {
+ // Call parent's method
+ this._super(attributes, options);
+ // some custom code here
+ // ...
+ }
+});
+```
## Namespacing

0 comments on commit 90aa66d

Please sign in to comment.