this经典试题
<body>
<div class="container">
<h3>输出内容</h3>
<pre>
var name = 'lili';
var obj = {
name: 'liming',
prop: {
name: 'ivan',
getname: function() {
return this.name;
}
}
};
console.log(obj.prop.getname());//ivan
var test = obj.prop.getname;
console.log(test()); //lili
试题解析:
谁调用这个方法,this就指向谁;
</pre>
</div>
<script>
var name = 'lili';
var obj = {
name: 'liming',
prop: {
name: 'ivan',
getname: function() {
return this.name;
}
}
};
console.log(obj.prop.getname());//ivan
var test = obj.prop.getname;
console.log(test()); //lili
</script>