我正在尝试在回调中保留this
变量:
var that = this
bootbox.confirm("This is the default confirm!", function(result){
console.log(that.whatever);
});
看起来很丑,还有更好的方法吗?
您可以使用箭头功能:
bootbox.confirm("This is the default confirm!", result => {
console.log(this.whatever);
});
尽管您应该使用Babel进行编译,older browsers may not support it。