4
试图创建一个从Backbone.Model
“继承”但重写sync
方法的骨干“插件”。创建骨干插件
这是我到目前为止有:
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');
}
的方法:Object.create()
直接从书的Javascript采取:好的部分:
Object.create = function(o){
var F = function(){};
F.prototype = o;
return new F();
};
我越来越尝试使用新型号时出现错误:
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'});
错误发生在Backbone 0.9.2开发版本的第1392行。功能inherits()
内:
Uncaught TypeError: Function.prototype.toString is not generic .
我试图创建的骨干库Marionette
创建视图的新版本的方式一个新的插件。 IT看起来像是误解了应该这样做的方式。
什么是创建骨干插件的好方法?
啊优秀,非常感谢!是的,我确实忽略了Object.create函数包装器,因为我想将帖子中的代码减少到最小。我工作的版本确实有封装。 – 2012-08-17 22:18:57