You should set this
for callback in Meteor.call
, because now this
refers to the global scope or undefined
if you are using strict mode
.(您应该设置this
在回调Meteor.call
,因为现在this
指的是全球范围或undefined
,如果你使用的是strict mode
。)
In JavaScript, there is method .bind
which allows set this
for method(在JavaScript中,方法.bind
允许为方法设置this
值)
Meteor.call("createClass", this.props.courseId, className, function(error) {
if (error) {
console.log(error.reason)
} else {
this.onSuccessCreateClass()
}
}.bind(this))
--(-)
Meteor.call("createNewClass", this.props.courseId, className, function(error) {
if (error) {
console.log(error.reason)
} else {
this.onSuccessCreateClass()
}
}.bind(this))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…