Using jQuery $(this) with ES6 Arrow Functions (lexical this binding)

$(document).on("change", "input", function(){
	$(this).val(); //輸出觸發事件元素的值
}
$(document).on("change", "input", () => {
	$(this).val(); //輸出觸發事件元素的值<--------這裡會報錯
}

<aside> 💡 一般而言,箭頭函式本體沒有自己的 this ,也因此函式內如果使用this,則會指向上一層

</aside>

$(document).on("change", "input", (e)=>{
	$(e.target).val(); //輸出觸發事件元素的值<--------可以正常使用了
}

<aside> 💡 留意target和currentTarget的差異 target是觸發事件真正啟動事件的元素本體 currentTarget則是觸發事件所指定監聽的元素

</aside>

<button type="button" id="XD" class="btn btn-primary">
	<i class="fas fa-share mr-2"></i>發布
</button>
$(document).on('click', 'XD', (e) => {
	console.log($(e.target));
	console.log($(e.currentTarget));
}