Javascript class获取回调函数数据
/********************************************************************** * Javascript class获取回调函数数据 * 说明: * 在使用Javascript class的时候,发现this指针和之前的理解有差异。 * * 2018-4-20 深圳 宝安西乡 曾剑锋 *********************************************************************/ 一、参考文档: 1. Access class member within callback when inside ES6 class statement https://stackoverflow.com/questions/39564038/access-class-member-within-callback-when-inside-es6-class-statement/39564078#39564078 二、解决方法: 1. 换别名: Load() { const that = this; chrome.storage.sync.get('somesetting', function (setting) { console.log(that.Object); } ); } 2. 采用=>进行处理: Load() { chrome.storage.sync.get('somesetting', setting => { console.log(this.Object); } ); }