我想重寫Backbone.Model構造函數與我自己的,爲了能夠從外部傳遞我的參數,而不是作爲創建對象。骨幹:無法重寫構造函數
這裏是我的代碼:
var Video = Backbone.Model.extend({
constructor : function (videoUrl,imageSource,title,rating,description,starsImageSource){
this.videoUrl = videoUrl;
this.imageSource = imageSource;
this.title = title;
this.rating = rating;
this.description = description;
this.starsImageSource = starsImageSource;
Backbone.Model.apply(this, arguments);
}
});
試圖進入
new Video("www.yahoo","coins.jpg","Yahoo",4,"hhhh","5stars.png")
以下錯誤,當出現: 類型錯誤:無效的 '在' 操作數OBJ 這裏是我的包括:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js" type="text/javascript"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script>
<script src="http://marionettejs.com/downloads/backbone.marionette.js" type="text/javascript"></script>
謝謝!
'Backbone.Model.apply(this,arguments)'無效。你必須使用Backbone.Model'構造函數的原型' – hindmost 2014-10-08 20:43:26
BTW:爲什麼你不使用'initialize'方法?它允許傳遞/接收參數 – hindmost 2014-10-08 20:45:50
我該怎麼做? – 2014-10-08 20:45:52