我想重写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