在引导箱回调函数中保留“ this”

问题描述 投票:1回答:1

我正在尝试在回调中保留this变量:

var that = this
bootbox.confirm("This is the default confirm!", function(result){ 
    console.log(that.whatever); 
});

看起来很丑,还有更好的方法吗?

vue.js bootbox
1个回答
1
投票

您可以使用箭头功能:

bootbox.confirm("This is the default confirm!", result => { 
    console.log(this.whatever); 
});

尽管您应该使用Babel进行编译,older browsers may not support it

© www.soinside.com 2019 - 2024. All rights reserved.