Javascript 在严格模式下禁止指向 this

如下代码, f() 输出的是 false,而 f2() 输出的是 true。
这是因为 f2 在严格模式下禁止 this 指向全局,所以 this 是 undefined, !this 当然是 true。

    <script>
        function f(){
            console.log(!this);
        }

        function f2(){
            "use strict";
            console.log(!this);
        }

        f();
        f2();
    </script>

posted on 2018-02-16 09:53  建伟F4nniu  阅读(149)  评论(0编辑  收藏  举报

导航