关于JS中this指向的说明

这几节讲一下JS中比较容易解释不清楚的语法问题

1.该节所讲为this指向问题:

<script type="text/javascript">

        var fullName = "111";
        var hello = {
            'fullName' : "333",
            'world' : {
                'fullName' : "555",
                'getFullName' : function(){
                    return this.fullName;
                },
            }
        }
        console.log(hello.world.getFullName());
        var test = hello.world.getFullName;
        console.log(test());

</script>

 

 上边JS代码分别打印结果为: 555   与   111

 this指代的是对象调用语法"."小数点之前的对象.  

JS代码最后一行,函数直接调用其实就是window.test(),所以会this指向的window对象

posted @ 2016-12-13 10:06  Sunny孙宁  阅读(139)  评论(0编辑  收藏  举报