3-4、箭头函数中的this指向

37 阅读1分钟
<script>
    // 1.箭头函数中的this指向
    // 箭头函数没有自己的this

    // const calc = {
    //     add: () => {
    //         console.log(this);
    //     }
    // }
    // calc.add(); // window

    // 2.练习
    // 'use strict'
    // const calc = {
    //     add: function () {
    //         const adder = () => {
    //             // this
    //             console.log(this);
    //         };
    //         adder();
    //     }
    // };
    // calc.add() //calc

    // const addFn = calc.add;
    // addFn(); // undefined -> window
</script>