js中function (res) {}與(res) =>{}的區別


這里是引用
function (res) {} 中 打印this時是undefined 打印that時是有內容的

                let that = this;
                getTotal().then(function (res) {
                    console.log(this);
                    console.log(that);
                    this.totalData = res.body.content;
                    this.total = res.body.total;
        })


結果

 

 


(res) =>{}中打印 this 和 that 都是有內容的

                let that = this;
                getTotal().then((res) =>{
                    console.log(this);
                    console.log(that)
                    this.totalData = res.body.content;
                    this.total = res.body.total;
                })

結果


 

 
原文鏈接:https://blog.csdn.net/qq_40121328/article/details/108828755


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM