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