Trying to create a basic "plugin" that "inherits" from Backbone.Model , but overrides the sync method.
This is what I have so far:
Backbone.New_Plugin = {}; Backbone.New_Plugin.Model = Object.create(Backbone.Model); Backbone.New_Plugin.Model.sync = function(method, model, options){ alert('Body of sync method'); }
Method: Object.create() was taken directly from Javascript: The Good Parts :
Object.create = function(o){ var F = function(){}; F.prototype = o; return new F(); };
I get an error when trying to use the new model:
var NewModel = Backbone.New_Plugin.Model.extend({}); // Error occurs inside backbone when this line is executed attempting to create a // 'Model' instance using the new plugin: var newModelInstance = new NewModel({_pk: 'primary_key'});
The error occurs on line 1392 of the Backbone 0.9.2 development version. inside the inherits() function:
Uncaught TypeError: Function.prototype.toString is not generic.
I am trying to create a new plugin so that the Marionette base library creates new versions of Views. It seems to me that I do not understand how this should be done.
What is a good way to create a new trunk plugin?
source share