码迷,mamicode.com
首页 > 其他好文 > 详细

this指向问题,只提供案例,不做任何分析

时间:2019-03-02 18:47:48      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:UNC   getname   foo   style   cal   color   on()   class   www.   

希望大家在测试的道路上找到答案,阔步前行

<script type="text/javascript">
            /*this指向
            
            console.log(this);
             
            function fn(){
                console.log(this);
            }
            fn();
            
            function Foo(){
                this.name="jhon";
                this.age=20;
                console.log(this);
            }
            var f1=new Foo();
            
            function Foo(){
                this.name="jhon";
                this.age=20;
                console.log(this);
            }
            Foo();
            
            var obj={
                x:10,
                fn:function(){
                    console.log(this);
                    console.log(this.x)
                }
            }
            obj.fn();
            
            var obj={
                x:10,
                fn:function(){
                    function f(){
                        console.log(this);
                        console.log(this.x)
                    }
                    f();
                }
            }
            obj.fn()
            
            var obj={
                x:10,
                fn:function(){
                    console.log(this);
                    console.log(this.x)
                }
            }
            var fn1=obj.fn;
            fn1();
            
            var obj={
                x:10
            }
            var fn=function(){
                console.log(this);
                console.log(this.x);
            }
            fn.call(obj);
            
            function Foo(){
                this.name="jhon";
                this.age=20;
            }
            Foo.prototype.getName=function(){
                console.log(this,this.name);
            }
            var foo=new Foo();
            foo.getName();*/
            
        </script>

  如果您实在不愿意自行分析理解,或者基础较为薄弱无力进行分析:请移步

  王福朋-博客园

this指向问题,只提供案例,不做任何分析

标签:UNC   getname   foo   style   cal   color   on()   class   www.   

原文地址:https://www.cnblogs.com/gitByLegend/p/10462175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!