Skip to content

Instantly share code, notes, and snippets.

@qustosh
qustosh / backbone.super.js
Created February 21, 2013 18:13
backbone extend with super
// Extend Backbone Classes with a 'super' function to execute a method of an instance's superclass
_.each(['Collection', 'Model', 'View', 'Router'], function(className) {
Backbone[className].prototype.super = function(funcName) {
var parentPrototype = this.constructor.__super__;
if (parentPrototype && typeof parentPrototype[funcName] === 'function') {
return this.constructor.__super__[funcName].apply(this, _.rest(arguments));
}
};
});
/**
* Simple localStorage with Cookie Fallback
*
* USAGE:
* ----------------------------------------
* Set New / Modify:
* store('my_key', 'some_value');
*
* Retrieve:
* store('my_key');