函数内this的指向问题

函数内this的指向问题

1 . 非严格模式下,this指向window

 function sum(a , b) {            //非严格模式下,this指向window
            console.log(this);
            return a + b
        }
        sum();

2. 严格模式下,this指向undefined

function sum(a, b) {             //严格模式下,this指向undefined
            "use strict";
            console.log(this);                  
            return a + b;
        }
        let c = sum(1,1);
        console.log(c);
posted on 2022-01-14 08:31  Steven_YF  阅读(27)  评论(0编辑  收藏  举报