猿问

一个奇怪的this指向问题

function haha(){                this.one=function(){                   
 console.log(this)
                }                this.two=function(){                   
                 this.one();                    console.log(this)
                }
                
            }var hehe = new haha()
hehe.two()

通过对象的属性调用,this不是应该指向这个对象的吗(hehe对象)?
为什么这里会输出两个haha对象呢.


慕尼黑5688855
浏览 500回答 1
1回答

精慕HU

因为hehe是Haha的一个实例名呀。你也可以叫做heihei。。。对于Haha类本身来说它是被调用者,是不感知你给他取什么实例名的。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答