【发布时间】:2018-01-05 22:07:00
【问题描述】:
我有这个代码,其中我的“this.index”和“this.result”是未定义的,我如何制作它以便当我更新它们的值时它就像通过引用传递一样:
submitQuiz(addsMemberPoints, pointsCallback) {
this.getValues(this.answers, this.totalPoints, this.index, function(answers, totalPoints, ranks, index){
pointsCallback(answers, ranks, addsMemberPoints, totalPoints, index, function(index, points){
function getMember(obj) {
return Object.keys(obj).reduce(function(a, b){ return obj[a] > obj[b] ? a : b });
}
// would like to change index and result of initial class with new values
this.result = getMember(points);
this.index = index;
});
});
}
产生的错误被重现
【问题讨论】:
标签: javascript angular typescript pass-by-reference