当我运行时++this.get('votes')
,我收到以下错误消息
Uncaught ReferenceError: Invalid left-hand side expression in prefix operation.
我得到了同样的错误信息++(this.get('votes'))
。
我能够解决这个问题,this.get('votes') + 1
但我不知道为什么前缀运算符不起作用。
为什么不应该this.get('votes')
评估为 0 然后变为 1 并返回值 1?
上下文中的原始代码:
var Comment = Backbone.Model.extend({
initialize: function(message) {
this.set({votes: 0, message: message});
},
upvote: function(){
// Set the `votes` attribute to the current vote count plus one.
this.set('votes', ++this.get('votes'));
}
}
var comment = new Comment('This is a message');
comment.upvote();