↗☻【this】

Javascript的this用法
http://www.ruanyifeng.com/blog/2010/04/using_this_keyword_in_javascript.html

关于Javascript语言中this关键字(变量)的用法
http://julying.com/blog/javascript-this/

深入理解Javascript之this关键字
http://www.laruence.com/2009/09/08/1076.html

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <script>
        /*
         * this代表函数运行时,自动生成的一个内部对象,只能在函数内部使用 
         * 随着函数使用场合的不同,this的值会发生变化。但是有一个总的原则,那就是this指的是,调用函数的那个对象
         */

        /*var global = this;
        console.log(global);*/

        /*function test() {
            console.log(this);
        }
        test();*/

        /*function test() {
            console.log(this);
        }
        var o = {};
        o.x = 1;
        o.m = test;
        o.m();*/

        /*var x = 2;
        function test() {
            this.x = 1;
        }
        var o = new test();
        console.log(x);*/

        var x = 0;
        function test() {
            console.log(this.x);
        }
        var o = {};
        o.x = 1;
        o.m = test;
        o.m.apply(); // apply()的参数为空时,默认调用全局对象
        o.m.apply(o);
    </script>
</body>
</html>
原文地址:https://www.cnblogs.com/jzm17173/p/2630661.html