5
การใช้ jQuery $ (this) กับ ES6 Arrow Functions (คำศัพท์การผูกนี้)
การใช้ฟังก์ชันลูกศร ES6 กับการthisผูกศัพท์นั้นยอดเยี่ยมมาก อย่างไรก็ตามฉันพบปัญหาเมื่อสักครู่ที่ผ่านมาโดยใช้กับการเชื่อมโยงการคลิก jQuery ทั่วไป: class Game { foo() { self = this; this._pads.on('click', function() { if (self.go) { $(this).addClass('active'); } }); } } ใช้ฟังก์ชันลูกศรแทน: class Game { foo() { this._pads.on('click', () => { if (this.go) { $(this).addClass('active'); } }); } } จากนั้น$(this)จะถูกแปลงเป็น ES5 (self = this) type closed …